Skip to reading
Buttons, Labels & Text Boxes

Save and restore the note explicitly

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 illustrations

Create a GDScript record called save_note. Connect the Save note button to it with the same run-visual-script event setup as Save Name.

Code example
extends "res://scripts/runtime/script_base.gd"
Code example
func run(_context: Dictionary = {}) -> Variant:
    var note: String = str(GetGUIElementProperty(
        "text_examples", "notes_box", "text", ""
    ))
    await SetVariable({"name": "notes_saved", "value": note})
    return true

Create a second GDScript record called restore_note and connect Restore note to it.

Code example
extends "res://scripts/runtime/script_base.gd"
Code example
func run(_context: Dictionary = {}) -> Variant:
    var note: String = str(Runtime.variables.get("notes_saved", ""))
    SetGUIElementProperty(
        "text_examples", "notes_box", "value", note
    )
    return true

Figure 25. The restored multiline text contains both saved lines. The script reads live text and writes the text-box value when refilling it.

A label containing Saved: $$notes_saved can show the stored note separately. Saving this variable is not the same as writing a text file. Game saves can preserve runtime variables; the draft control still needs an intentional restore step when your UI is rebuilt or reopened after loading.

Page 33 of 46Permalink
Go to page