Waiting in any scene

Status
Not open for further replies.

Jono99

Veteran
Veteran
Joined
May 8, 2015
Messages
76
Reaction score
17
First Language
English
Primarily Uses
RMVXA
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.
 
Last edited by a moderator:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,381
Reaction score
8,537
First Language
English
Primarily Uses
RMMV
I've moved this thread to RGSS Support. Please be sure to post your threads in the correct forum next time. Thank you.
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,434
Reaction score
7,713
First Language
German
Primarily Uses
RMMV
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...
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
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:

  1. 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.

  2. 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).
 

Jono99

Veteran
Veteran
Joined
May 8, 2015
Messages
76
Reaction score
17
First Language
English
Primarily Uses
RMVXA
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:

  1. 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.

  2. 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.
 
Last edited by a moderator:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,381
Reaction score
8,537
First Language
English
Primarily Uses
RMMV
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.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,546
Members
137,835
Latest member
yetisteven
Top