Skip to reading
Buttons, Labels & Text Boxes

The complete Check Answer script

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
Code example
extends "res://scripts/runtime/script_base.gd"
Code example
func run(_context: Dictionary = {}) -> Variant:
    var entered: String = str(GetGUIElementProperty(
        "register_panel", "answer_box", "text", ""
    )).strip_edges().to_upper()
Code example
    if entered != "CLOCK":
        await SetVariable({
            "name": "feedback",
            "value": "That is not the word. Try CLOCK."
        })
        return false
Code example
    if bool(Runtime.variables.get("register_open", false)):
        return true
    await SetVariable({"name": "register_open", "value": true})
    await ChangeVariable({
        "name": "score", "operation": "add", "value": 5
    })
    await SetVariable({
        "name": "feedback",
        "value": "The register unlocks. Five points earned."
    })
    await SetVariable({
        "name": "objective",
        "value": "Read the newly opened register."
    })
    await DisableGUIElement({
        "guiId": "register_panel", "elementId": "answer_submit"
    })
    return true

Use answer_submit as the Check answer button's ID. The script disables that specific button after a correct answer. Replace these explicit IDs if your controls have different ones.

The flag is the reward guard. The disabled button is a useful presentation choice, but the flag still protects the reward if the script is called from somewhere else.

Page 30 of 46Permalink
Go to page