Explain what you're trying to do, not how you're trying to do it.
If it's what I'm thinking, you might be able to do the whole thing without scripts at all.
I agree with Shaz.
It seems that the player needs to push the red orb on top of the red button and the green orb on top of the green button. Is that all that you want to achieve? Because just that can be coded a WHOLE lot simpler and shorter and probably without those variables.
The code that you could place in a red orb to check if it is on top of the red button:
# call like this: check2(event_id) # no need to replace "event_id". # returns true if this orb is on top of the red button. Returns false otherwise. def check2(ev_id) $game_map.events[ev_id].x == 5 && $game_map.events[ev_id].y == 4 endNow you can create a simple conditional branch and voila it works. Unless you were trying to do something else 😛 . But in that case we need more information.
Oh and use different coordinates for the green button of course. But this is only 1 script line and you wouldn't even need a whole method for it depending on how many buttons you will be using in your project.
You don't even need scripting to do that. It can all be done with events. Which is why I asked what the goal was - there are several tutorials and examples that show you how to do a simple "push this object to that spot" puzzle with events.
Yes but then you have to 'mess around' with so many event-lines and perhaps some autorun/parallel events that consume unnecessary resources and such which can be a pain on big maps. Scripts are faster and easier for me personally.
But again, I do agree with you. It can be done with just events and regions and such. There is no need for scripting. Unless of course I misunderstood the OP's goals for that puzzle.
You obviously don't know how much I detest parallel process events 😉 I would not recommend doing it via events if wasn't as good as, or as easy as, doing it via scripts. And you don't need really complex events to do it.
With enough effort quite everything can be done with events. I already know it. Im just learning to script, so I do basic things.
I want to get feedback on the code, things I havent done good and how I could improve the code and so on.
Im just thinking that i could wrote this better, and for example without using the class variables.
Its difficult for me to explain what Iam doing in english but I try:
check_event_pos(id, connect, static)
"id" = the EventID(@event_id,the whole time)
"static" can be true or false.
If its true it means that the function will check the events position it is called in and the position of other connected events and return true or false.
(its mean to be used on the switches which run with a parallel process)
If static is false it means, than it will just save the x and y pos of the event it is called in.
(it is mean to be run on the "stone"-events so if the stone get moved the x and y pos will change)
And "connect" will connect the stone with the switch. Connect should be a number.E.g. a switch will only proc. if the stone on it have the same number in connect like the switch. So like you see on the demo you can create 2 switches easily, which run separated from another.
I hope you understand what i mean. Just look at the demo and Ì think you will understand.
To understand the first part you have to learn how regular expressions work. Just google for "regular expressions" (preferably for ruby). It is used to search in strings and to perform string-based actions like in this case: "<button: red 1>" is put in an array as [:red, 1] but ONLY if it starts with "button:" and not counting the "<". It's hard to explain for me. Better just look it up there are guides that can explain it much better.
def reset; $active_ball_game = Ball_Game.new; endequals:
def reset $active_ball_game = Ball_Game.newendAnd the code below assigns a new Ball_Game class to the global variable (Yeah I started using global variables instead of singletons because RPG Maker stripped out the singleton library > 🙁 and creating one manually looks so messy imo). Screw it 😛 .
$active_ball_game = Ball_Game.new"Ball_Game.reset" would crash or at best do nothing at all. "Ball_Game" is the class and NOT a variable. The variable is "$active_ball_game" and you want to reset a variable and not a 'class definition'. See the example below:
class Foo def hello; p 'hello'; endend@a = [email hidden] # <<<<< works and prints 'hello'# You do NOT write:Foo.hello # <<<< crashes probablyThe only exception is when you have a 'static' method like "def self.hello()".
The advantage for using this code is that creating new ball games is very easy (just add the comment tags and the move-away-from-player and voila). No more fiddling around with event-lines in every new ball or button. It also uses no auto-run and no parallel processes and is only executed when moving a ball and when a game_map is loaded so it hardly consumes any resources unless you have like 200.000 events on 1 single map...
Thanks I now understand it fully, i just had a mind blockade on that variable thing.
And yes I will look into regular expressions. Iam watching the video tutorials from diamondandplatinum and I have seen that he have made a video that covers regular expressions.
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.