I need a timer script for my game. It needs to be able to be controlled by events. you also need to be able to add time to the timer in-game while it is running. The timer needs to include decimals of seconds (i.e. 4.3 seconds). Also, I need to be able to manipulate it with events to say that "if the timer is over 5 min, then A", or "if the timer has finished counting, then B". I really need this for my game.
I'm pretty sure you can do all of that with the default timer. You can start and stop the timer with the control timer command. You can also use a parallel processes even to set a variable to equal what the timer says and then use a conditional branches on that variable. Unfortunately, I don't think RMXP can handle decimals with variables or the timer.
RMXP uses the frame counter for the timer and the frame counter has a precision of 1/40 seconds. If you open Sprite_Timer, you should be able to find these lines quickly:
@total_sec = $game_system.timer / Graphics.frame_rate
# Make a string for displaying the timer
min = @total_sec / 60
sec = @total_sec % 60
text = sprintf("%02d:%06.3f", min, sec)#sprintf("%02d:%02d", min, sec)
Change them to this:
@total_sec = $game_system.timer / Graphics.frame_rate.to_f
# Make a string for displaying the timer
min = @total_sec.to_i / 60
sec = @total_sec % 60
text = sprintf("%02d:%05.2f", min, sec)
You can use "%02d:%06.3f" for the format if you want 3 digits after the seconds counter, but anything above that won't be displayed as the precision is only 1/40 (which equals 0.025 seconds).
[Invalid and downright silly comment about Blizzard returning to rmxp]
So I watched a video on youtube about timer events
http://www.youtube.com/watch?v=kQj_T0KN0qk (http://www.youtube.com/watch?v=kQj_T0KN0qk)
And it showed how to do everything except how to add time to the timer in-game and while it is running. Any ideas?
Also, Blizz, for your script rewrite, do I just type 3.025 in the seconds box of the timer for it to work
To add time to the timer, use:
$game_system.timer += 40 # Adds one second to the time
$game_system.timer -= 1 # Removes 1/40 of a second from the time
$game_system.timer = 800 # Sets timer to 20 seconds
With blizzard's script replacement, does it turn the second or the minutes into frames? :???: