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

imported>Morerunes
m (Added StopQuest to used commands)
 
(5 intermediate revisions by 3 users not shown)
Line 3: Line 3:
For this exercise, we shall be creating a simple timer that displays a message after a certain amount of time passes.
For this exercise, we shall be creating a simple timer that displays a message after a certain amount of time passes.


{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]}}


== Requirements ==
== Requirements ==
Basic knowledge of:
Basic knowledge of:
* Scripting in Oblivion
* Coding
* The [[Tescs|Construction Set]] and it's usage
* The [[Tescs|Construction Set]] and its usage
 


== Commands and Functions used ==
== Commands and Functions used ==
Line 16: Line 16:
* [[GetSecondsPassed]]
* [[GetSecondsPassed]]
* [[Message]]
* [[Message]]
* [[StopQuest]]




Line 101: 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