To be useful, persistent variables must be mutated. Persistents can only be mutated in the postlude.
Info | ||
---|---|---|
| ||
The syntax for use with the node pico engine differs. There is no |
The following statements mutate persistent variables:
...
<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:
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;
app:b{["flip", "flop"]} := "this is a string";
ent:c := null
} |
Deprecated
Info | ||
---|---|---|
| ||
The following are deprecated and should not be used. |
...