Keep settings in a JSON file
BASIC IN YOUR GAME
JSON stores named values in a text file. It works well for a preference like “show hints” because the name and value stay together.
FUNCTION Run()
DIM path = "user://station/options.json"
DIM prefs = ReadJSONFile(path, {"hints": TRUE})
prefs.hints = FALSE
IF NOT WriteJSONFile(path, prefs) THEN
RETURN "Write failed"
END IF
DIM loaded = ReadJSONFile(path, {})
RETURN loaded.hints
END FUNCTIONFor a missing or unreadable setting, the starting dictionary supplies hints = TRUE. The script changes hints to FALSE and writes the dictionary. It then reads it back. The returned FALSE is the value of hints. The text Write failed is the separate failure result.
A successful JSON parse can still produce the wrong kind of data. This listing expects a dictionary. If another tool or an older edition of your game can write the same file, check the structure and supply defaults for missing fields before using them.
