Skip to reading
PCA Script Programming

14. Dictionaries and your own records

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
record Reward
    item: text
    points: integer
end
Code example
function 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"]]
end

A 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.

Page 21 of 357Permalink
Go to page