Skip to reading
Save Games & Inventory

Use the event context in a small 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(event_context: Dictionary = {}) -> Variant:
    var slot_number: int = int(
        event_context.get("saveSlot", -1))
    if slot_number < 0:
        return false
    var caption: String = "Slot " + str(slot_number)
    if bool(event_context.get("saveExists", false)):
        caption += ": " + str(event_context.get("saveName", ""))
    else:
        caption += ": empty"
    await SetVariable({
        "name": "save_feedback", "value": caption
    })
    return true

1. Create a GDScript record with this source and apply it.

2. Select the Save Game Widget, open Events and assign the record to Click using the script-running behavior.

3. Keep the built-in Click slot action at select while testing.

4. Show $$save_feedback in a separate Label.

5. Click several rows. The Label should describe each clicked slot without performing a save.

The context belongs to this input. If the subsequent built-in action creates a save, this script has already run. Use a later explicit file query when you need the state after completion.

Page 66 of 96Permalink
Go to page