Global and local variables are useful when you want to compute some variable from the participant's responses and store this variable for later use.
get_global(key, state) set_global(key, value, state) get_local(key, state) set_local(key, value, state) assert_global_is_null(key, state)
The variable's key (character scalar).
Value to set the variable to.
get_local return the respective
variables with key equal to
NULL if the
variable has yet to be defined.
You can set global or local variables within expressions that are
run during the participant's testing session,
for example in code blocks (
on_complete functions (see
The variable will be preserved for the duration of the participant's
testing session until it is overwritten.
For tests without modules,
global and local variables behave the same.
The difference between local and global variables is that
local variables are encapsulated within a given module (
and are wiped at the end of the module (
get_local to get variables.
set_local to set them.
assert_global_is_null throws an error if the specified global variable
NULL. This is useful to catch cases where the code
would otherwise overwrite a pre-existing variable.