Difference between revisions of "GetSecondsPassed"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Haama
(Standardizing (though separating Warnings from Notes on other functions might be a good idea))
imported>Fella
Line 35: Line 35:


[[Category: Functions]]
[[Category: Functions]]
[[Category:Functions (CS)]]
[[Category: Functions (CS 1.0)]]
[[Category: Functions (CS 1.0)]]
[[Category: Time Functions]]
[[Category: Time Functions]]
[[Category: Time Functions (CS 1.0)]]
[[Category: Time Functions (CS 1.0)]]

Revision as of 12:36, 23 January 2008

Syntax:

GetSecondsPassed 

Returns the number of seconds passed since the last game frame (in float). Extremely useful for running a timer within a script. Each script has its own counter for GetSecondsPassed and when the function is called, this counter is automatically reset to 0. Thus, all subsequent calls within the same frame and script will return 0.


Example:

float timer

begin gamemode

if timer > 0
   set timer to timer - GetSecondsPassed
else
   ; time's up! Do something.
endif

end

If timer is set to any positive value (representing seconds to count down), it will be decremented fractionally with every frame, until it reaches 0, at which point the else clause will be executed. The else clause should probably contain some kind of "DoOnce" catch, unless it is supposed to be executed every frame, once the timer runs down.

Example Two:

 float timer1
 float timer2
 
 begin gamemode
 set timer1 to getsecondspassed  ;This returns the time passed since the last frame
 set timer2 to getsecondspassed  ;This returns zero

 end

Notes