Is it possible to have something similar to the wait command in any scene. Fiber.yeild doesn't work because scenes run on the root fiber and therefore cannot yeild. I have succeeded in making a window dedicated to calculating time passing by opening and closing over and over, but that solution is rather sloppy. Is there any other way? Thanks.
Waiting in any scene
RGSSx Script SupportI've moved this thread to RGSS Support. Please be sure to post your threads in the correct forum next time. Thank you.
Can you describe what you want to wait for?
Because basically the gametime is stopped while in all menu screens as well as the battlescene, so a wait doesn't make any sense there...
Because basically the gametime is stopped while in all menu screens as well as the battlescene, so a wait doesn't make any sense there...
I guess, he can wait for button press, for an animation, for a movement of an object, and for many other reasons.
You can make your own "wait" methods inside the update method of the object you work in (in this case, it's in a scene class, if I got it right).
You can do it two ways:
These update methods are just examples, you can do other things to wait for something without a timer too.
For example, if you need to check for a button press, you can still make a branch in your update method, check for the existence of a variable (which will activate this check), and if the variable is defined, do a button trigger check, and inside that check, do whatever you want, and at the end, disable this check by setting the variable to nil.
And so on, it's all about using condition checks, variables and logic.
You can also use conditioned loops too (such as while and until), but that is a bit more advanced. If you happen to use those, be aware that you must explicitly tell the loop what should it execute, since nothing will be executed inside of it by default (so, no Graphics.update or Input.update either, nor will your scene's update method run inside).
You can make your own "wait" methods inside the update method of the object you work in (in this case, it's in a scene class, if I got it right).
You can do it two ways:
- Make a timer. It is a simple numeric variable which counts either up or down (depends on your update logic for the timer). When you trigger that something you want to wait for, you set the timer to the time you want to wait (in frames). In the update method, you make a condition of:
if @timer <= 0
# do normal stuffs here
else
@timer -= 1 # timer counting down here
# do anything else what you want to happen during the waiting time here
end
With this, you separated the update method into 2 parts, one will happen when there is no waiting time set, the other will happen when there is a waiting time.
Save the current time (or the Graphics.frame_count) into a variable when you trigger that something you want to wait for. In the update method, you need to make a condition again, like this:
if @trigger_time # Only check for this if there is a saved trigger time
if @trigger_time + 600 >= Graphics.frame_count
# this means that the waiting time is over, 10 seconds has passed
# add anything else you want to trigger when the timer has run out here too
@trigger_time = nil # disables this check, since we don't need it anymore
else
# this means the waiting time is still in effect
# do whatever you want to happen during the waiting time here
end
end
This will check if 10 seconds has been passed since the start of the timer (600 frames = 10 seconds). If yes, do something and deactivate the timer check (or restart it if you need). If no, do something else, or just wait for the timer.
These update methods are just examples, you can do other things to wait for something without a timer too.
For example, if you need to check for a button press, you can still make a branch in your update method, check for the existence of a variable (which will activate this check), and if the variable is defined, do a button trigger check, and inside that check, do whatever you want, and at the end, disable this check by setting the variable to nil.
And so on, it's all about using condition checks, variables and logic.
You can also use conditioned loops too (such as while and until), but that is a bit more advanced. If you happen to use those, be aware that you must explicitly tell the loop what should it execute, since nothing will be executed inside of it by default (so, no Graphics.update or Input.update either, nor will your scene's update method run inside).
Thank you very much! The second method worked like a charm.
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.
Original thread: https://forums.rpgmakerweb.com/threads/waiting-in-any-scene.69428/