Skip to content

Namespace

CommandNamespace
namespace {local|global|clear|push|pop|copy} [parameters...]

Also searchable as: Namespace · ! variables · shared variables · scope

A namespace is a named set of ! variables. At any moment one namespace is current, and every !x in the script means the variable x of that namespace. Switching namespaces gives a sub its own variables, or lets several scripts share some.

  • Local namespaces belong to one script tab: no other script sees them.
  • Global namespaces are shared by every script running in EasyUO Reforged, in any tab.

A script starts in the local namespace std. #NSName and #NSType tell which namespace is current.

Command What it does
namespace local Makes a local namespace current.
namespace global Makes a global namespace current.
namespace push Remembers the current namespace.
namespace pop Goes back to the namespace last remembered.
namespace copy Copies variables between the current namespace and another.
namespace clear Deletes every variable of the current namespace.

% variables are not affected by namespaces: they always belong to the script.

A sub that works in its own namespace, so it cannot overwrite the caller’s ! variables:

set !count 10
gosub work
gosub work
display ok !count ; still 10
halt
sub work
namespace push
namespace local work
set !count !count + 1
namespace pop
return

See also

Based on the EasyUO wiki, edited for EasyUO Reforged. This text is available under the GNU Free Documentation License 1.2.