14. Dictionaries and your own records
record Reward
item: text
points: integer
endfunction run()
let reward = Reward(item: "key", points: 5)
let facts = {"unlocked": false, "attempts": 0}
facts["attempts"] += 1
facts["unlocked"] = true
return [reward["points"], facts["attempts"]]
endA dictionary stores values under keys. Use quoted text keys, and use brackets to read a key held in another variable: facts[key_name]. A simple named field can also use dot access. For a missing dictionary key, the value is null; check before doing arithmetic with it.
A record declaration defines the fields of a data value. The named-argument constructor above produces a dictionary with those fields. It does not create a character, import an asset or register a new designer object. A project record reference, such as objects.archive_door, is a different kind of value.
Arrays and dictionaries are mutable containers. For an independent deep copy of JSON-compatible data,
from_json(to_json(value)) is a useful technique. Vectors, colors and live record references are not a promise of lossless JSON round-tripping.
