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

Added usage details
imported>Shademe
m (→‎Mechanics: Minor Corrections)
imported>Morerunes
(Added usage details)
Line 100: Line 100:


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.
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