reset - coldrockgames/doc-scriptor GitHub Wiki
For performance reasons, the script variables of a script are not reset between runs by default. This can become very handy, if you want to do things in your scripts (like counting things) over several executions of a script.
It can, however, be necessary to reset everything to default now and then. Normally, there's no reason to do this, but if you need it, the reset
command will do exactly that.
Syntax
A simple, straightforward command without any parameters.
reset
A Note About Performance
reset
can not simply set the internal variable store to {}
, because that would create an entirely new struct to store the variables. Especially in conjunction with the call command, this could break pointers, shared variables would no longer work.
Therefore, the reset
command must take a "soft" approach of cleaning the variables of a script. What this command internally does is:
var names = struct_get_names(_exe.vars);
for (var i = 0, len = array_length(names); i < len; i++)
struct_remove(_exe.vars, names[@i]);
It removes all known variables from the internal store, one by one in a loop. This is the only way to ensure, all pointers stay intact, as no new instance of a struct is generated. It has the drawback of impacting performance, therefore:
[!CAUTION] Due to the requirement of preserving existing pointers, the
reset
command is quite slow and can impact performance.
Use it only, when you really have to!
The better approach would be to design your scripts in a way, where areset
is never necessary!