Difference between revisions of "GetSecondsPassed"
Jump to navigation
Jump to search
imported>JustTheBast (Added expanded explanation to first example.) |
imported>ZuTheSkunk (See also) |
||
(8 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
'''Syntax:''' | '''Syntax:''' | ||
GetSecondsPassed | (seconds:float) GetSecondsPassed | ||
Returns the number of seconds passed since the last | Returns the number of seconds passed since the last frame in which the current script was processed (in float). Extremely useful for running a timer within a script. Each script has its own counter for GetSecondsPassed. All calls within the same frame and script will return the same value. | ||
Line 27: | Line 27: | ||
begin gamemode | begin gamemode | ||
set timer1 to getsecondspassed ;This returns the time passed since the last frame | set timer1 to getsecondspassed ;This returns the time passed since the last frame | ||
set timer2 to getsecondspassed ;This returns | set timer2 to getsecondspassed ;This returns the same value | ||
end | end | ||
== Notes == | |||
* GetSecondsPassed is unreliable in a ScriptEffect during sleep/wait/fast travel. Use [[ScriptEffectElapsedSeconds]] instead. | |||
== See also == | |||
* [[Scripting Tutorial: Creating a Simple Timer]] | |||
[[Category: Functions]] | [[Category: Functions]] | ||
[[Category:Functions (CS)]] | |||
[[Category: Functions (CS 1.0)]] | |||
[[Category: Time Functions]] | [[Category: Time Functions]] | ||
[[Category: Time Functions (CS 1.0)]] | |||
<!-- Begin Search Terms | |||
Get | |||
Seconds | |||
Passed | |||
End Search Terms --> |
Latest revision as of 15:00, 5 May 2010
Syntax:
(seconds:float) GetSecondsPassed
Returns the number of seconds passed since the last frame in which the current script was processed (in float). Extremely useful for running a timer within a script. Each script has its own counter for GetSecondsPassed. All calls within the same frame and script will return the same value.
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 the same value end
Notes[edit | edit source]
- GetSecondsPassed is unreliable in a ScriptEffect during sleep/wait/fast travel. Use ScriptEffectElapsedSeconds instead.
See also[edit | edit source]