Hi,
Just a quick tutorial on how to create a countdown timer. It's incredibly easy to set up a countdown timer loop, but this tutorial covers a few extra touches like separating the timer into minutes and seconds and prefixing a zero to the seconds counter when below 10.
Start off by creating the variables needed, which are...
(Name) (Type) (Initial Value)
TimeLimitMinutes, Whole Number, 5
TimeLimitSeconds, Whole Number, 0
TimeLimitPreSecond, Whole Number, 0
TimeLimitUnderTen, Whole Number, 1
TimeLimitReached, Whole Number, 0
TimeLimitSeparator, Text, ":"
TimeLimitString, Text, ""
Next, head to the CScript editor and create the following function...
function FormatTimer()
{
TimeLimitStringLogicVariableValue := ""
AppendString(TimeLimitStringLogicVariableValue, TimeLimitMinutesLogicVariableValue)
AppendString(TimeLimitStringLogicVariableValue, TimeLimitSeparatorLogicVariableValue)
if(TimeLimitUnderTenLogicVariableValue=1)
{
AppendString(TimeLimitStringLogicVariableValue, TimeLimitPreSecondLogicVariableValue)
}
AppendString(TimeLimitStringLogicVariableValue, TimeLimitSecondsLogicVariableValue)
}
Create a group in your logic and initialise the variables as follows, along with an initial call to FormatTimer().
This group needs to go somewhere near the start of your logic, along with the rest of your initialisation nodes. Next create another group, which manages to countdown timer, as seen below...
Place this group wherever in your logic you want the timer to start counting down. When it is finished, it sets TimeLimitReached to 1, so just use a variable test or a variable watch on this variable at the relevant place in your logic in order to perform the next action after the timer has ran out. In order to change the time limit length, just initialise the TimeLimitMinutes variable to whatever value you want.
In order to display your countdown timer, simply use {TimeLimitString} as the text parameter for a HUD text box, or similar.
