Methods
# archiveReplacer(_key, value) → {*}
The JSON.stringify replacer used when saving a game. JSON cannot represent
a Set (it would be written as {}) so a Set is replaced by {json$safe: true, type: "set", value: [...members]}, the same marker archiveInto() uses for functions. Because it is
applied by JSON.stringify it also finds Sets nested inside lists and records. The inverse
is archiveReviver().
Parameters:
| Name | Type | Description |
|---|---|---|
_key |
string
|
property name being serialized (unused) |
value |
*
|
property value being serialized |
the value, with any Set replaced by a json$safe wrapper
*
# archiveReviver(_key, value) → {*}
The JSON.parse reviver used when loading a game, the inverse of
archiveReplacer(). Other json$safe wrappers (functions) are left for loadData().
Parameters:
| Name | Type | Description |
|---|---|---|
_key |
string
|
property name being deserialized (unused) |
value |
*
|
property value being deserialized |
the value, with any json$safe Set wrapper turned back into a Set
*
# evaluateExpression(expression, bindings, rvalopt) → {*}
Evaluates a JavaScript expression string with access to provided bindings.
Creates a sandboxed function that can access binding values by name, then executes it with those values. Used by templates for conditionals and dynamic expressions.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
expression |
string
|
The JavaScript expression to evaluate |
||
bindings |
Object
|
Object mapping variable names to their values |
||
rval |
boolean
|
<optional> |
true | If true, wraps expression in return statement |
The result of evaluating the expression
*
Examples
// Evaluate a conditional
evaluateExpression("score > 10", { score: 15 }); // returns true
// Evaluate without return value (for side effects)
evaluateExpression("console.log(name)", { name: "Player" }, false);
# normalizeRefs(value) → {*}
Recursively normalizes reference objects in attribute values. The Rez compiler
outputs element references as {$ref: "element_id"} objects. This function collapses them
to plain ID strings for simpler runtime handling. Handles primitives, arrays, Sets, and
plain objects. Special object types (RezDie, Map, etc.) pass through unchanged.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
*
|
any value that may contain $ref objects |
the value with all {$ref: "id"} objects collapsed to plain "id" strings
*