Advanced timer

Started by The Amazing Link, January 07, 2012, 04:18:15 pm

Previous topic - Next topic

The Amazing Link

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.
Spoiler: ShowHide
*leaves without sword* *beats game anyways*

Boba Fett Link

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.
This post will self-destruct in 30 seconds.

Blizzard

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).
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

The Niche

[Invalid and downright silly comment about Blizzard returning to rmxp]
Level me down, I'm trying to become the anti-blizz!
Quote from: winkio on June 15, 2011, 07:30:23 pm
Ah, excellent.  You liked my amusing sideshow, yes?  I'm just a simple fool, my wit entertains the wise, and my wisdom fools the fools.



I'm like the bible, widely hated and beautifully quotable.

Dropbox is this way, not any other way!

The Amazing Link

So I watched a video on youtube about timer events

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
Spoiler: ShowHide
*leaves without sword* *beats game anyways*

ForeverZer0

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

I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

The Amazing Link

With blizzard's script replacement, does it turn the second or the minutes  into frames? :???:
Spoiler: ShowHide
*leaves without sword* *beats game anyways*