To be useful, persistent variables must be mutated. Persistents can only be mutated in the postlude.
...
title | Engine Compatibility |
---|
The
...
The following statements mutate persistent variables:
clear <pvar>
. This deletes the persistent variable<pvar>
.- set
<pvar> := <expr>
. This sets assigns the value of<pvar>
to the value of the expression (literal). <expr> to <pvar>.
<pvar>
can contain a hash path referencing part of the structure. Warning |
---|
For historical reasons, if the persistent variable does not exist before it is used, the default value is 0. This means that the isnull() operator, for example, is never true for an entity variable. |
Warning |
---|
Numbers don't behave well as persistent variable indexes for maps. This is due to the underlying Mongo implementation treating them as array references rather than as map (hash) keys. In general, prepending or appending a string to the number will fix the problem. |
Examples
For classic KRE:
...
language | javascript |
---|---|
theme | Confluence |
Example
Code Block |
---|
fired { set ent:a 1 set app:b{"foo"} 1 + my_var set app:b{["flip", "flop"]} "this is a string" clear c } |
This blog post has a detailed example of using persistent variables to create a personal data manager.
For the node pico engine:
Code Block |
---|
fired { ent:a := 1; app:b{"foo"} := 1 + my_var.defaultsTo(0); app:b{["flip", "flop"]} := "this is a string"; ent:c := null } |
Deprecated
Info | ||
---|---|---|
| ||
The following are deprecated and should not be used. |
...
clear ent:a
} |