How do I add a timer?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

Easily, actually! You're looking for the set timer command:

plotscript, setup timer, begin
  set timer(0, 300, 18, @my script)
end

This will set the first (0th) timer to 300 "seconds", with 18 ticks per "second". When it runs out, it will run "my script". Easy as pie!

But, it doesn't show up on screen![edit]

That is for flexibility, see. set timer takes a fifth parameter, the number of a string. If you give it a string, it will update the string every time it counts down. Then, you can place this string anywhere on the screen you want using show string at.

plotscript, setup timer, begin
  set timer(0, 300, 18, @my script, 1)
  show string at(1, 280, 190) #show the timer in the bottom-right corner of the screen
end

It will take the form "m:ss", which will look like "1:52", or "0:02" or similar.

Hey, it pauses during battle![edit]

Oh, you didn't say you wanted it to run in battle. That's easy enough, using the last parameter of set timer, flags. You can give a timer a number of flags, which include:

  • timerflag: battle - causes the timer to show up and run during battle
  • timerflag: critical - causes the battle to end if the timer expires during it
  • timerflag: menu - causes the timer to run while the player is browsing the menu (still in progress)

You can combine flags using the or operator: timerflag:battle, or, timerflag:critical

plotscript, setup timer, begin
  set timer(0, 300, 18, @my script, 1, timerflag:battle, or, timerflag:critical)
  show string at(1, 280, 190) #show the timer in the bottom-right corner of the screen
end

Now, if your timer runs out during battle, the battle will end right then and there, and the script will run.

=See Also[edit]