Skip to reading
BASIC Scripting

Pause a script without freezing the room

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

BASIC IN YOUR GAME

WAIT takes seconds. A tenth of a second is 0.1. While this script waits, the game can keep drawing the room and listening for input.

Code example
FUNCTION Run()
    PRINT "First chime"
    WAIT 0.1
    PRINT "Second chime"
    RETURN "done"
END FUNCTION

The output shows First chime, then Second chime. The script returns done after the second line. Use a longer wait when the pause should be noticeable to the player.

Code example
FUNCTION Run()
    DIM ready = TRUE
    WAIT UNTIL ready
    RETURN "Ready"
END FUNCTION

WAIT UNTIL asks a yes-or-no question. Here ready is already true, so the result is Ready immediately. In a game, use a shared flag that a button or another event can change. A local flag set to FALSE and never changed would leave the script waiting.

A deadline the game can remember#

Code example
signal_deadline = NowUnix() + 30
remaining = Max(0, signal_deadline - NowUnix())

These are two separate fragments. Declare signal_deadline as a GLOBAL Integer and use DIM remaining for the local calculation. Use the first line when the clock starts. Use the second whenever you display the seconds left. NowUnix reads the device clock, so time away from the game counts too.

Page 20 of 86Permalink
Go to page