Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: The Amazing Link on January 07, 2012, 04:18:15 pm

Title: Advanced timer
Post by: The Amazing Link on January 07, 2012, 04:18:15 pm
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.
Title: Re: Advanced timer
Post by: Boba Fett Link on January 07, 2012, 04:26:10 pm
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.
Title: Re: Advanced timer
Post by: Blizzard on January 07, 2012, 05:06:57 pm
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).
Title: Re: Advanced timer
Post by: The Niche on January 07, 2012, 09:57:57 pm
[Invalid and downright silly comment about Blizzard returning to rmxp]
Title: Re: Advanced timer
Post by: The Amazing Link on January 12, 2012, 06:18:39 pm
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
Title: Re: Advanced timer
Post by: ForeverZer0 on January 12, 2012, 07:44:30 pm
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

Title: Re: Advanced timer
Post by: The Amazing Link on January 17, 2012, 06:59:04 pm
With blizzard's script replacement, does it turn the second or the minutes  into frames? :???: