Skip to reading
Save Games & Inventory

22. Use the same operations in scripts

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 slot_number: int = int(GetGUIElementProperty(
        "save_lab", "save_slots", "selected_slot", -1))
    if slot_number < 1:
        await SetVariable({
            "name": "save_feedback",
            "value": "Choose a manual slot first."
        })
        return false
    await SaveGameWidgetCommand({
        "guiId": "save_lab",
        "elementId": "save_slots",
        "command": "save-selected",
        "slot": -1
    })
    return true

This Button script adds a guard before dispatching the normal widget command. With dedicated autosave 0, a manual choice must be at least 1. The widget still owns naming, overwrite confirmation and its mode/range rules.

The final true means the script dispatched the command. It does not mean the player finished the name dialog or accepted an overwrite. Do not award an achievement simply because this record returned true.

If you reserve a positive slot for autosave, adjust the guard to exclude that number too. The simple less-than-1 check only matches this workshop’s slot policy.

Page 67 of 96Permalink
Go to page