Skip to reading
Lua Scripting

Use Godot from a Lua record

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 19

Draw a temporary overlay using Godot controls. Keep the node alive until the timer finishes, then free it.

Code example
local Script = {}
Code example
function Script.run(context)
    local layer = ClassDB:instantiate("CanvasLayer")
    Runtime:add_child(layer)
    local swatch = ClassDB:instantiate("ColorRect")
    swatch.color = Color(0.08, 0.29, 0.34, 1.0)
    swatch.position = Vector2(24, 32)
    swatch.size = Vector2(270, 48)
    layer:add_child(swatch)
    local label = ClassDB:instantiate("Label")
    label.text = "Archive signal received"
    label.position = Vector2(12, 8)
    swatch:add_child(label)
    await(Wait(1.5))
    layer:queue_free()
    return true
end
Code example
return Script

Run from a game session. A teal rectangle with a label appears near the top left, then disappears.

CanvasLayer draws its control children in screen space. The rectangle owns the label in the scene

tree. Freeing the layer frees the temporary controls together. For production HUDs, set mouse_filter

to ignore on decorative controls that would otherwise intercept clicks.

Godot values use constructors such as Vector2 and Color. Godot objects expose methods through

Lua's colon syntax. For persistent native nodes, choose a parent whose lifetime matches the

feature. A separately authored Godot drawing class can implement _draw and be called from Lua

through a native PCA record when the overlay needs custom drawing.

Page 37 of 133Permalink
Go to page