Difference between revisions of "Scripting Tutorial: Creating a Simple Timer"

Reverted to last revision made by Shademe
imported>Morerunes
m (Added StopQuest to used commands)
imported>Shademe
(Reverted to last revision made by Shademe)
* [[GetSecondsPassed]]
* [[Message]]
* [[StopQuest]]
 
 
 
The '''doOnce''' variable is used to make sure the initialization happens only once, i.e., during the script's first iteration. But this method not preferable as it calls more comparisons, is longer and needs initialization.
 
If you use a timer in your own mod, it may be helpful to make a new quest such as MRFiveSecondTimerQuest with the five second timer script on it (replace MR with whatever your initials are, or whatever your alias is to avoid other mod conflicts). Then when you want to initialize the timer, just call StartQuest <questName> and it should run the timer. Then you can replace the "Time's Up" message to set a variable, or do something else if you like. Also, make sure you call StopQuest <questName>, or it will continue to use system resources.
 
<pre>scn MRFiveSecondTimerQuestScript
 
float timer
float fQuestDelayTime
 
short doOnce
 
begin gamemode
set fQuestDelayTime to 0.001
 
if ( doOnce == 0 )
set timer to 5 ; Initialize the timer variable
set doOnce to 1
endif
if ( timer > 0 )
set timer to timer - getSecondsPassed
else
Message "Your 5 seconds are up"
StopQuest MRFiveSecondTimerQuest
endif
end</pre>
 
 
Anonymous user