Difference between revisions of "Scripting Tutorial: Creating a Simple Timer"
Scripting Tutorial: Creating a Simple Timer (edit)
Revision as of 19:39, 12 September 2023
, 19:39, 12 September 2023→Requirements
imported>Qazaaq m (adding internal links) |
|||
(8 intermediate revisions by 4 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: | ||
* | * Coding | ||
* The [[Tescs|Construction Set]] and | * The [[Tescs|Construction Set]] and its usage | ||
== Commands and Functions used == | == Commands and Functions used == | ||
Line 54: | Line 54: | ||
When the condition evaluates false i.e., when the timer variable's value equals or exceeds 5, our message is displayed. Since '''getSecondsPasssed''' returns values that are comparable to realtime seconds, the script has effectively run for 5 seconds. | When the condition evaluates false i.e., when the timer variable's value equals or exceeds 5, our message is displayed. Since '''getSecondsPasssed''' returns values that are comparable to realtime seconds, the script has effectively run for 5 seconds. | ||
But the script doesn't end here - it keeps | But the script doesn't end here - it keeps printing the message since the if condition checks only if the timer's value equals or exceeds 5. The If statement's condition can be modified to walk through this issue by adding a do-once catch. | ||
<pre>scn timerTestScript | <pre>scn timerTestScript | ||
Line 66: | Line 66: | ||
if ( doOnce ) ; the == operator isn't necessary when checking boolean values.... | if ( doOnce ) ; the == operator isn't necessary when checking boolean values.... | ||
return | return ; ... the above expression is equivalent to (doOnce != 0) | ||
elseif( timer > 5 ) | elseif( timer > 5 ) | ||
set doOnce to 1 | set doOnce to 1 | ||
Message "Your 5 seconds are up" | |||
else | else | ||
set timer to timer + getSecondsPassed | set timer to timer + getSecondsPassed |