Skip to reading
Lua Scripting

Read input from an authored GUI

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 09

Wire a text box and a button so the player can actually type the answer.

Create a GUI with ID archive_panel. Add a single-line text box answer_entry, a button check_answer

and a label feedback. Use unique element IDs. Make the panel visible during play. Leave Clear on

Enter and parser submission off for this button-driven exercise.

Code example
local Script = {}
Code example
function Script.run(context)
    local text = GetGUIElementProperty(
        "archive_panel", "answer_entry", "text", "")
    local answer = await(CallScript(
        "archive_words", "normalize", Array{tostring(text)}))
    local reply = "Try the direction on the label."
    if answer == "" then
        reply = "Type a direction first."
    elseif answer == "west" then
        reply = "The latch clicks."
    end
    SetGUIElementProperty("archive_panel", "feedback", "text", reply)
    return reply
end
Code example
return Script

Apply archive_words from the functions lesson. In the button's click action, choose the action that

runs a script and select read_answer. If using Call Script Function, expose run with no authored

parameters first. Apply the GUI, save and start Play. Type a space, WeSt, and another space. Click

the button. The label should read “The latch clicks.”

If every click produces the empty-answer response, check the GUI ID and the live text-box element ID.

The final empty string in the getter is the fallback for a missing property.

Page 27 of 133Permalink
Go to page