<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://elanthipedia.play.net/index.php?action=history&amp;feed=atom&amp;title=Timer_%28script%29</id>
	<title>Timer (script) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://elanthipedia.play.net/index.php?action=history&amp;feed=atom&amp;title=Timer_%28script%29"/>
	<link rel="alternate" type="text/html" href="https://elanthipedia.play.net/index.php?title=Timer_(script)&amp;action=history"/>
	<updated>2026-05-06T01:12:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://elanthipedia.play.net/index.php?title=Timer_(script)&amp;diff=630904&amp;oldid=prev</id>
		<title>SHIFT3: Created page with &quot;{{Script |cat=information |fe=Genie |auth=User:Shift3 }}  Include this script into your genie scripts to have a timer functionality.  Works cross script.    To import, sav...&quot;</title>
		<link rel="alternate" type="text/html" href="https://elanthipedia.play.net/index.php?title=Timer_(script)&amp;diff=630904&amp;oldid=prev"/>
		<updated>2023-11-19T23:56:29Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Script |cat=information |fe=Genie |auth=&lt;a href=&quot;/index.php?title=User:Shift3&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;User:Shift3 (page does not exist)&quot;&gt;User:Shift3&lt;/a&gt; }}  Include this script into your genie scripts to have a timer functionality.  Works cross script.    To import, sav...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Script&lt;br /&gt;
|cat=information&lt;br /&gt;
|fe=Genie&lt;br /&gt;
|auth=[[User:Shift3]]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Include this script into your genie scripts to have a timer functionality.  Works cross script.    To import, save the script as Timer.cmd and type: &amp;quot;include timer.cmd&amp;quot; (without the quotes) at the top of your script.  &lt;br /&gt;
&lt;br /&gt;
If anyone else wants it, see below.  Just include it into whatever script you&amp;#039;re using and then use one of the following commands:&lt;br /&gt;
&lt;br /&gt;
`gosub Timer.Refresh &amp;lt;timername&amp;gt;` - Updates this timer&lt;br /&gt;
&lt;br /&gt;
`gosub Timer.Reset &amp;lt;timername&amp;gt;` - Sets the timer back to 0&lt;br /&gt;
&lt;br /&gt;
`gosub Timer.SetTime &amp;lt;timermane&amp;gt; &amp;lt;seconds&amp;gt;` Sets the time to this value, backdates the start time.  &lt;br /&gt;
&lt;br /&gt;
All three functions above will store the response in both the global vars var `$Timer.&amp;lt;timername&amp;gt;.elapsed`  and `$Timer.&amp;lt;timername&amp;gt;.start` for when the timer start is in gametime.  &lt;br /&gt;
&lt;br /&gt;
- Two local vars `%Timer.lastVarName` and `%Timer.lastVarTime` are refreshed every time one of the three functions above are run. &lt;br /&gt;
&lt;br /&gt;
- If the timer didn&amp;#039;t exist then it&amp;#039;ll be created as part of the call.  &lt;br /&gt;
&lt;br /&gt;
- will update the timer and store the results of the timer in  `%Timer.lastVarName` = name of the timer, and `%Timer.lastVarTime` = time in seconds that have elapsed since start up to the last refresh. &lt;br /&gt;
&lt;br /&gt;
I&amp;#039;ve noticed a variance of 1-3 seconds due to rounding on `$gametime` and processing time.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
### import script only - meant to be used in other scripts - uses global variables that persist across sessions ###&lt;br /&gt;
&lt;br /&gt;
goto Timer.Imported&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
### -------------------------------------------------------------------------------------------------&lt;br /&gt;
### ---- Actual timer code&lt;br /&gt;
### -------------------------------------------------------------------------------------------------&lt;br /&gt;
# starts the timer if it&amp;#039;s not set&lt;br /&gt;
# call this before reading a timer&lt;br /&gt;
# single word timers&lt;br /&gt;
# timers are global and not reset when scripts start and shared across scripts&lt;br /&gt;
# Common timers: &lt;br /&gt;
	#   - almanac = last time read an almanac&lt;br /&gt;
	#   - spider = HE spider gift&lt;br /&gt;
	#   - cube = he cube gift&lt;br /&gt;
&lt;br /&gt;
Timer:&lt;br /&gt;
	var Timer.lastVarTime -1&lt;br /&gt;
	var Timer.lastVarName NULL&lt;br /&gt;
&lt;br /&gt;
	### internal function only ###&lt;br /&gt;
	### Calling this in your script creates an infinite loop&lt;br /&gt;
	Timer.INTERNAL.Verify.Exists:&lt;br /&gt;
		pause .0001&lt;br /&gt;
		if !($Timer.%Timer.lastVarName.elapsed &amp;gt;= 0) then {&lt;br /&gt;
			put #var Timer.%Timer.lastVarName.start $gametime&lt;br /&gt;
			put #var Timer.%Timer.lastVarName.elapsed 0&lt;br /&gt;
		}&lt;br /&gt;
	return&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	### public functions ###&lt;br /&gt;
	Timer.Refresh:&lt;br /&gt;
		pause .0001&lt;br /&gt;
		var Timer.lastVarName $1&lt;br /&gt;
&lt;br /&gt;
		gosub Timer.INTERNAL.Verify.Exists&lt;br /&gt;
&lt;br /&gt;
		MATH Timer.TMP set $gametime&lt;br /&gt;
		MATH Timer.TMP subtract $Timer.%Timer.lastVarName.start&lt;br /&gt;
		put #var Timer.%Timer.lastVarName.elapsed %Timer.TMP&lt;br /&gt;
		var Timer.lastVarTime $Timer.%Timer.lastVarName.elapsed&lt;br /&gt;
	return&lt;br /&gt;
&lt;br /&gt;
	#hardcodes a timer with seconds $1 = timer, $2 = seconds&lt;br /&gt;
	#example: gosub SetTimer myTimer 200&lt;br /&gt;
	#if timer hasn&amp;#039;t started, it starts it first&lt;br /&gt;
	#sets start time to current - seconds&lt;br /&gt;
	Timer.SetTime: &lt;br /&gt;
		pause .0001&lt;br /&gt;
		var Timer.lastVarName $1&lt;br /&gt;
		var Timer.lastVarTime $2&lt;br /&gt;
&lt;br /&gt;
		gosub Timer.INTERNAL.Verify.Exists&lt;br /&gt;
		var Timer.tmp $gametime&lt;br /&gt;
		MATH Timer.tmp SUB %Timer.lastVarTime&lt;br /&gt;
		put #var Timer.%Timer.lastVarName.start %Timer.tmp&lt;br /&gt;
		gosub Timer.Refresh %Timer.lastVarName&lt;br /&gt;
	return&lt;br /&gt;
&lt;br /&gt;
	Timer.Reset: &lt;br /&gt;
		pause .0001&lt;br /&gt;
		gosub Timer.SetTime $1 0&lt;br /&gt;
	return&lt;br /&gt;
&lt;br /&gt;
	### returns &lt;br /&gt;
	Timer.Pause:&lt;br /&gt;
		put #echo red &amp;gt;ScriptLog  Pause Timer not implemented&lt;br /&gt;
&lt;br /&gt;
return&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
### -------------------------------------------------------------------------------------------------&lt;br /&gt;
### ----   Unit tests for the functions above; shows usage&lt;br /&gt;
### -------------------------------------------------------------------------------------------------&lt;br /&gt;
### unit testing ###&lt;br /&gt;
&lt;br /&gt;
20231119.UnitTest:&lt;br /&gt;
	gosub 20131119.testTimer alchemyApp Timer.Reset&lt;br /&gt;
	gosub 20131119.testTimer alchemyApp Timer.Refresh&lt;br /&gt;
	gosub 20131119.testTimer alchemyApp Timer.SetTime 999&lt;br /&gt;
&lt;br /&gt;
	gosub 20131119.testTimer alchemyAppB Timer.Refresh&lt;br /&gt;
	gosub 20131119.testTimer alchemyAppB Timer.Reset&lt;br /&gt;
	gosub 20131119.testTimer alchemyAppB Timer.Refresh&lt;br /&gt;
&lt;br /&gt;
goto Timer.UnitTestComplete&lt;br /&gt;
&lt;br /&gt;
20131119.TestTimer:&lt;br /&gt;
	var tmp $1 $3&lt;br /&gt;
	gosub $2 %tmp&lt;br /&gt;
	put #echo &amp;gt;Log ---- $2 -----&lt;br /&gt;
	put #echo &amp;gt;Log green --- fed: %tmp&lt;br /&gt;
	put #echo &amp;gt;Log blue --- name: %Timer.lastVarName&lt;br /&gt;
	put #echo &amp;gt;Log yellow --- time: %Timer.lastVarTime&lt;br /&gt;
	put #echo &amp;gt;Log pink --- Debbug start: $Timer.%Timer.lastVarName.start  Debug Elapsed: $Timer.%Timer.lastVarName.elapsed&lt;br /&gt;
	pause 5&lt;br /&gt;
return&lt;br /&gt;
&lt;br /&gt;
### -------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Timer.UnitTestComplete:&lt;br /&gt;
Timer.imported:&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>SHIFT3</name></author>
	</entry>
</feed>