Skip to content

Add a bounded round timer

Build on the shared score counter. This tutorial teaches Wait, loops, and round state without creating an endless task chain.

Create Public Boolean roundActive and Public Number secondsLeft. Set roundActive false and secondsLeft 0 on Plot Start.

Create a static method RunRound, mark it Async, and give it a bounded countdown body. To start, set roundActive true and secondsLeft 10, then call RunRound. Use Await Off only if the starting event should continue independently.

Method: RunRound (Static, Async, Void)
Repeat Multiple Times: 10
Wait: 20 ticks
If: roundActive is true
Set Variable → Subtract Numbers (-)
Result: Public Number secondsLeft
Left Operand: Public Number secondsLeft
Right Operand: 1
Else
Return From Function
Set Variable: Public Boolean roundActive ← false

Choose an applicable Boolean condition/equality for the If. A nominal 20 ticks is one second when the server meets its tick target; it is not a wall-clock timing guarantee.

Before starting, check roundActive. If already true, return or show a message. This prevents repeated interactions from spawning overlapping countdowns.

For games that can restart a round before the old timer finishes, add a Public Number round identifier. Capture it as a Private parameter and recheck it after every Wait. Exit if it differs. Otherwise an old task could modify the new round’s counters.

Test a normal ten-step round, attempted duplicate start, early cancellation, and program stop/recompile. Inspect /plot diagnostics to confirm tasks finish instead of accumulating. Stopping the plot cancels its async work.