Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Timer Counting Upwards

I don't know if this is possible without a script...

Anyway, what I'm looking for is the ability to have the Timer count up, instead of down. At the end of specific events, depending on how much time it takes you, a variable is used to determine how long it took you to accomplished your goal.

I'm not looking to cancel out the countdown, as I intend to use that in my game as well. I need it to work both ways. So, if anyone can help me out, I would greatly appreciate it.
 
Ok, Seph's gonna give me shit for not aliasing command_124, but this works.
And, I don't think anything else in the game sets the timer, so it should be safe.

Paste it above main

Code:
# Modify Game_System.update and Interpreter.command_124
# to allow for an upward counting timer.
# 11DEC07 - Brew

class Game_System
  def update
    # reduce timer by 1
    if @timer_working == 1 and @timer > 0
      @timer -= 1
    end
    if @timer_working == 2
      @timer += 1
    end
  end
end

class Interpreter

  #--------------------------------------------------------------------------
  # * Control Timer
  #--------------------------------------------------------------------------
  def command_124
    # If started
    if @parameters[0] == 0
      $game_system.timer = @parameters[1] * Graphics.frame_rate
      $game_system.timer_working = 1
      if @parameters[1] == 0
              $game_system.timer_working = 2
      end
    end
    # If stopped
    if @parameters[0] == 1
      $game_system.timer_working = false
    end
    # Continue
    return true
  end
end

The nice part is you don't need a script command to use it.
If you use the event command to start the timer with a 00:00 value, the timer will count up.
Otherwise, it will function as normal and count down.

Be Well
 
The Timer still seems to work fine, but now I have another question. Is there a way to show how much time was left on the Timer in a Message Window? I've tried using a variable, but all it shows is the time in seconds.
 

poccil

Sponsor

Any Ruby object can be used as a variable, including strings, arrays, and hashes.  The following script code stores the time left on the timer in an RPGXP variable:

Code:
def getTimer(variableNumber)
      total_sec = $game_system.timer / Graphics.frame_rate
      min = total_sec / 60
      sec = total_sec % 60
      text = sprintf("%02d:%02d", min, sec)
      $game_variables[variableNumber]=text
end

Note that the RPGXP variable is now a string; the game will accept it just fine.  Example of use in a Script event command (putting the timer in variable 1):
Code:
getTimer(1)
 
I haven´t tested poccil´s suggestion but it makes sense and looks interesting... This is only possible because Game_Variables does not make any type check on the attributions, so any thing you try to attribute to a variable index gets stored.
BTW, what happens if you put a message command with this?

Code:
Time: \v[1]

:D

Oh, just make sure to NOT use any event commands involving variables calculations with a variable that has a string, or you can get neat errors sometimes.
 
Linkin_T":1ukrisrl said:
I haven´t tested poccil´s suggestion but it makes sense and looks interesting... This is only possible because Game_Variables does not make any type check on the attributions, so any thing you try to attribute to a variable index gets stored.
BTW, what happens if you put a message command with this?

Code:
Time: \v[1]

:D

Oh, just make sure to NOT use any event commands involving variables calculations with a variable that has a string, or you can get neat errors sometimes.

Say that there's 1:07 on the Timer. It will read back as '67'. I already tried that before I asked. I'll try poccil's suggestion. Great! It works! Thanks!
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top