Editing Scripting Tutorial: Creating a Simple Timer

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 16: Line 16:
* [[GetSecondsPassed]]
* [[GetSecondsPassed]]
* [[Message]]
* [[Message]]
* [[StopQuest]]




Line 100: Line 101:


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>




Please note that all contributions to the Oblivion ConstructionSet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see CSwiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Template used on this page: