Skip to reading
Lua Scripting

Timers, parallel actions and clocks

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

LESSON 10

Leave time for an animation or a sound while the game continues to process frames.

Code example
local Script = {}
Code example
function Script.run(context)
    local values = await(Parallel(
        function()
            await(Wait(0.05))
            return "short"
        end,
        function()
            await(Wait(0.10))
            return "long"
        end
    ))
    return tostring(values[0]) .. "/" .. tostring(values[1])
end
Code example
return Script

Expected result: short/long. Each branch is a function. Parallel starts the branches together and

waits for all of them. The returned Godot array keeps the original branch order. Wait takes seconds.

Use await(Wait(0.5)) between two sequential cues for a half-second pause.

A wait resumes the same invocation. A different button or scene event can run while it is waiting.

Before changing a room-specific control afterward, verify CurrentScene() and the puzzle state. For a

countdown that survives save/load, explicitly keep the remaining time or deadline in project state.

DateTimeString(true) returns a UTC timestamp for a journal. NowUnix() gives wall-clock seconds.

For measuring short performance intervals use Godot's monotonic Time:get_ticks_msec(). Calendar

changes can move wall-clock time backward.

Page 28 of 133Permalink
Go to page