Event Wait Command

eventWaitCommand1.jpg



This script introduces a new command that allows you to tell an event to stop and wait until a certain condition is met before proceeding.


RPG Maker comes with a wait command, but that is only to check whether a certain amount of frames have passed before proceeding. This custom wait command allows you to condition on things such as the value of a switch or variable, player input, or anything else that you can imagine that can be done with formulas.


The command is provided in two formats: a marked up conditional branch, or a script call so that you can choose which one you are most comfortable with.


Get it at HimeWorks!


Personally I haven't come up with any practical uses for this, so if you have any ideas what kind of opportunities this creates do share them.


So for example the screenshot above starts by displaying a message, and then it will wait. It will continue to wait until the variable reaches 20. Once the variable reaches 20, it will then proceed to display another message.


Another common use case is waiting for a certain key to be pressed (or any key for that matter).
Ooooh.
Oh finally, thank you. I knew something was missing from RM when fiddling with multiple event pages became really tricky, depending on what switches were on, etc. This is especially true for the 'wait for X key to be pressed'!

I'll give this a try soon.
This is especially true for the 'wait for X key to be pressed'!
That was pretty much the question I had in mind when I wrote this: "How can I make it so that the event simply does not proceed until I press the S key?"


The next question I had was "How can I make it so that pressing one key will do one thing, but pressing another key will do another?"


I think the second problem can be solved by having a wait condition on those two keys, and then right after the wait condition is over, it will enter regular conditional branches that check the appropriate key.
Yes, I use pathfinding and often tell the player or an NPC to go to a spot on the map and want the event to wait until they get there. Next iteration of the mouse script (or the pathfinding part) will include an option to wait until they reach that spot, but in the meantime, I've used a common event that continually loops, checking the position of the event/NPC, and exits once they reach the desired spot. Something like this would allow the same thing, in fewer lines of code.
Oooh... this makes things a little bit shorter (compared to using a loop with a cond branch and wait inside). :3

PS: Never actually tested that method so far. XD
Oooh... this makes things a little bit shorter (compared to using a loop with a cond branch and wait inside). :3


PS: Never actually tested that method so far. XD
Using a loop would cause the game to freeze if you're not using a parallel process.


This method allows you to loop indefinitely without freezing up everything else even if it's action trigger.
Using a loop would cause the game to freeze if you're not using a parallel process.
It won't freeze regardless of the event's trigger type if you do it like this:
# Event stops here until button press...# Loop# Conditional Branch > Input.trigger?🙂button)# Break Loop# Else# Wait(1)# End# Repeat Above# Event continues here after button press...I used this method countless times for quick-time events with animated pictures. 😛 But your script here can do so much more! *-*

It is definitely another great eventing tool, thanks a lot for it!
It won't freeze regardless of the event's trigger type if you do it like this:

# Event stops here until button press...# Loop# Conditional Branch > Input.trigger?🙂button)# Break Loop# Else# Wait(1)# End# Repeat Above# Event continues here after button press...I used this method countless times for quick-time events with animated pictures. 😛 But your script here can do so much more! *-*

It is definitely another great eventing tool, thanks a lot for it!
Thanks, I figured there was an equivalent way using loop and the existing wait, since the approach is basically the same.

I don't think my script would actually do more; it would just be short-hand.

It also doesn't give you control over how fast it checks the condition, or a timed conditional wait.
I just went and evented a few events with some tricky conditioning with the wait command.


You are right, everything can be evented with the loop+condition+wait commands.


Regardless, your script makes it in fewer lines on the event page, and that is always a plus for me.


Finding something on an event page with 200+ lines is just not fun. 😀


Without your script it takes 7 lines for one waiting condition.


With your script it takes only 4, so 3 lines saved per waiting condition which is awesome. 🙂
The way you implemented Game_Interpreter#wait_until doesn't really make much sense and could cause some performance issues -- there's just no good reason to take a string and convert it into a closure via eval when Ruby methods already implicitly take blocks anyway. Instead of taking a string and using eval to convert it into a new instance of Proc each time that method is called, just use the block you can already pass to the method in any case:

class Game_Interpreter def wait_until Fiber.yield until yield endend# Usage in a script call:wait_until { Input.trigger?🙂C) }This evades the (slow) usage of eval and uses an existing object rather than creating a new one -- and if you used eval to ensure that someone sends an argument to the method, using yield will generate a LocalJumpError if no block is given to the method (similar to how yours would raise an ArgumentError without a string).Just a suggestion.
The way you implemented Game_Interpreter#wait_until doesn't really make much sense and could cause some performance issues -- there's just no good reason to take a string and convert it into a closure via eval when Ruby methods already implicitly take blocks anyway. Instead of taking a string and using eval to convert it into a new instance of Proc each time that method is called, just use the block you can already pass to the method in any case:

class Game_Interpreter def wait_until Fiber.yield until yield endend# Usage in a script call:wait_until { Input.trigger?🙂C) }This evades the (slow) usage of eval and uses an existing object rather than creating a new one -- and if you used eval to ensure that someone sends an argument to the method, using yield will generate a LocalJumpError if no block is given to the method (similar to how yours would raise an ArgumentError without a string).Just a suggestion.
That would be cleaner and probably more ruby than passing a string of ruby syntax.

I was thinking of providing variable shortcuts like s or v, but then decided not to.

Kind of curious whether passing something like

Code:
wait_until { v[1] == 2}
Could be evaluated in a given context where v == $game_variables
They're already in a script call; nothing is stopping them from defining local variables. As for whether or not you could make those shortcuts, well... yes, you could, but that doesn't really seem necessary to me.
They're already in a script call; nothing is stopping them from defining local variables. As for whether or not you could make those shortcuts, well... yes, you could, but that doesn't really seem necessary to me.
I prefer providing variables because I think it improves user experience. It's like "you can use this variable to reference this other thing" in case someone that's using it knows how to use variables through damage formulas but doesn't know anything about global variables.
I prefer providing variables because I think it improves user experience. It's like "you can use this variable to reference this other thing" in case someone that's using it knows how to use variables through damage formulas but doesn't know anything about global variables.
How would someone that knows enough code to code a script condition for the wait_until thingy not know how to make v = $game_variables one line before using the wait command?

Overcomplicating things for the sake of making them look more complex than they actually are is never a good idea.

You could even use the following in a script call instead:

Code:
Fiber.yield until Input.trigger?(:SHIFT)#/ some condition
Assuming we will force the user to do this via script calls... which if they know how to do, won't even need the script at all...

The way I see it, this is useful for those who wants this functionality while being able to simply use the normal methods that can be utilized via the non-script conditional branch options... while minimizing lines as we have seen that we can just do this via loop+cond.branch+wait
How would someone that knows enough code to code a script condition for the wait_until thingy not know how to make v = $game_variables one line before using the wait command?
If someone's learning how to write formulas based on damage formulas, I think it's a reasonable assumption that someone might not be aware how 'v' came about.

Of course they could simply learn ruby.

Overcomplicating things for the sake of making them look more complex than they actually are is never a good idea.

You could even use the following in a script call instead:

Fiber.yield until Input.trigger?🙂SHIFT)#/ some condition
Maybe. The script call itself was an after-thought and thrown in there in case someone said "conditional branch is too long why can't I just make a script call"

It was modeled after formulas and so ended up just being an eval.
If someone's learning how to write formulas based on damage formulas, I think it's a reasonable assumption that someone might not be aware how 'v' came about.
fnnlw.jpg
The instructions were made so that someone that only has knowledge about damage formulas would be able to take that knowledge and apply it to a script call.

Original thread: https://forums.rpgmakerweb.com/threads/event-wait-command.35154/