Plotscript of the Month
Counter, by Moogle1
Download an example of this script in action

This is an example script that will run an invisible counter that persists through battles and menus. You can use this script to see how long a battle took, to make an escape sequence, or to measure time for any other purpose. Note that this is only useful if you want to measure elapsed clock time. If you want to measure clock ticks, this is not the script for you.

# COUNTER # Original author: Moogle1
include,plotscr.hsd

define script(1,start counter,none)
define script(autonumber,total mins,none) #returns minutes (total)
define script(autonumber,total secs,none) #returns seconds (total)
define script(autonumber,ct secs,none) #returns seconds (from 0 to 59)
define script(autonumber,ct mins,none) #returns minutes (from 0 to 59)
define script(autonumber,ct hrs,none) #returns hours (total)

global variable (2,start min) #start minutes
global variable (3,start hr) #start hours
global variable (4,start sec) #start seconds

script, start counter, begin
set variable(start min, minutes of play)
set variable(start hr, hours of play)
set variable(start sec, seconds of play)
# simple enough, just sets the starting variables to the current playtime.
end

script, ct secs, begin
variable(rvar) #"return variable"
rvar := seconds of play -- start sec
if (rvar << 0) then (rvar := rvar + 60)
return (rvar)
end

script, ct mins, begin
variable(rvar)
rvar := minutes of play -- start min
if (seconds of play << start sec) then (decrement(rvar))
if (rvar << 0) then (rvar := rvar + 60)
return (rvar)
end

script, total mins, begin
variable (rvar)
rvar := ct mins + (ct hrs * 60)
return (rvar)
end

script, total secs, begin
variable (rvar)
rvar := ct secs + (total mins * 60)
return (rvar)
end

script, ct hrs, begin
variable (rvar)
rvar := hoursofplay -- start hr
if (minutes of play << start min) then (decrement(rvar))
rvar := rvar + days of play * 24 # I don't want to know why you would need this kind of counter
if (rvar << 0) then (rvar := rvar + 24)
end

# NEW CODE
global variable (5, end min)
global variable (6, end sec)
global variable (7, total sec)

define script(2,end counter,none)

script, end counter, begin
if (total sec == 0) then # if timer is unset, then set it
(
total sec := total secs
end sec := ct secs
end min := ct mins
# for the purposes of this example, we'll assume you didn't take an hour
)
show text box (12) # You took X minutes and Y seconds
show value (total sec)
wait for text box

# show a different text box depending on how long it took
if (total sec << 60) then (show text box (14))
else (show text box(13))
end

Usage
Run startctr first. You can use the other scripts to find how much time has elapsed since you called startctr.

These scripts should be used in conjunction with other scripts. For example, to check if two and a half minutes have passed, you could use the following code:

if (total secs >> 150) then (...) # 150 secs = 2 1/2 min

The script will not automatically tell you when a certain amount of time has passed. You need to check the elapsed time via other scripts.

Download an example of this script in action