- Joined
- Jul 4, 2014
- Messages
- 2,162
- Reaction score
- 823
- First Language
- Hungarian
- Primarily Uses
- RMVXA
The update method itself is a "loop", you don't need another loop.
Here is an example from one of my scripts:
This whole thing is inserted in the update method.
Let's see what's happening here...
First, the @counter is initialized with a value of 0.
The @phase is another variable which decides what will be run when the counter condition is true. This way you can use a single counter and make separate stuffs happen depending on another variable. Optional part, but useful for making many things happen based on the value of this variable.
The @effs[@phase] is a hash, which lets you make infinite phases by simply adding new keys and setting their value to an integer. This way you can make separate countdowns for each of your phases. Completely optional, this can simply be a static number if you don't need different timing for different stuffs on the scene.
In the update method, the @counter is incremented by 1 on each frame.
In every frame, there is a condition which checks if the counter has reached a specific value or not.
If it did, it runs a method based on the current @phase and sets the next phase accordingly.
At the end, still in the condition check, the @counter is reset to 0, so it can start to count again until it reaches the next phase time.
Now that you got this, you can insert different methods into the update method.
These methods would only run when the counter reached the defined value.
No idea what are you trying to do, but whatever it is, if it needs timing, you need to meddle in the update method directly, and make your conditions in it cleverly, so that the methods in the update method run only when you want them to.
Here is an example from one of my scripts:
@counter += 1 # Adding 1 to the counter each frame. if @counter >= @effs[@phase] # A variable to check against the counter. case @phase # Checking the current phase. when :start do_starting_phase # This runs when the counter reaches 0 the first time. @phase = :idle # Setting the next phase. when :idle do_idle_phase # This runs when the counter reaches 0. Got a different phase. @phase = :end # Setting the next phase. when :end do_ending_phase # Runs when the counter reaches 0. Yet another phase. @phase = :dispose # Setting the next phase. end @counter = 0 # Resetting the counter each time at the end. end
Let's see what's happening here...
First, the @counter is initialized with a value of 0.
The @phase is another variable which decides what will be run when the counter condition is true. This way you can use a single counter and make separate stuffs happen depending on another variable. Optional part, but useful for making many things happen based on the value of this variable.
The @effs[@phase] is a hash, which lets you make infinite phases by simply adding new keys and setting their value to an integer. This way you can make separate countdowns for each of your phases. Completely optional, this can simply be a static number if you don't need different timing for different stuffs on the scene.
In the update method, the @counter is incremented by 1 on each frame.
In every frame, there is a condition which checks if the counter has reached a specific value or not.
If it did, it runs a method based on the current @phase and sets the next phase accordingly.
At the end, still in the condition check, the @counter is reset to 0, so it can start to count again until it reaches the next phase time.
Now that you got this, you can insert different methods into the update method.
These methods would only run when the counter reached the defined value.
No idea what are you trying to do, but whatever it is, if it needs timing, you need to meddle in the update method directly, and make your conditions in it cleverly, so that the methods in the update method run only when you want them to.

