Debugging a Lua record
On this page
LESSON 22
Work from the first observable failure. A working script with a wrong record ID often looks like a button that does nothing.
The source fails validation#
Check for a missing end, an unfinished string, a misplaced return or a copied smart quote. Keep
top-level code limited to declarations. Try the first record unchanged and reintroduce one function
at a time.
The record runs, but the interaction does nothing#
Put Log("entered archive_unlock") on the first executable line of run. No log points to the event or
button wiring or the record's enabled state. A log followed by no feedback points to the getter, GUI
visibility, element ID or setter. Capture the Boolean returned by SetGUIElementProperty to
distinguish lookup failure.
A number or collection has the wrong shape#
Log(type(value)) and Log(tostring(value)) separately. Native Godot values may be userdata. Wrap
an engine string in tostring before applying Lua patterns. Check whether you received a Lua table
or a Godot Array before choosing index 1 or 0.
Catch an error in a pure helper#
local Script = {}function Script.run(context)
local ok, result = pcall(function()
local n = tonumber("bell")
assert(n, "A numeric dial setting is required.")
return n * 2
end)
if not ok then Log(tostring(result)) end
return ok
endreturn ScriptExpect false and the diagnostic in the log. Reserve assertions for assumptions you control. A wrong
puzzle answer is normal input and deserves an in-game hint.
