User variables are special variable fields that can be created in an actor's DECORATE and used for various scripting purposes. Contrarily to the args, user variables are guaranteed not to be used by any pre-existing feature, so they can be used without risk of conflict with obscure functions.
A user variable must be declared in an actor's code with a line of this form:
var int user_<name>; var float user_<name>; (development version only)
Floating point and string variables are not supported at the moment. Note that the declaration ends with a semicolon. All user variable names are prefixed with "user_" to prevent any risk of conflict with future features.
As of (development version only), floating point is now supported by both ACS and Decorate. While GetUserVariable is capable of retrieving non-user variables including strings and names, SetUserVariable is still restricted to user variables of int or float only.
It is also possible to declare arrays, using the square bracket notation to indicate a size:
var int user_<name>[<size>];
var int user_foo; var int user_bar;
This creates the user_foo variable and the user_bar array with 42 elements, accessible in DECORATE expressions through user_bar to user_bar.
Several conditions apply when working with user variables, due to the complexity of certain actor classes.
- The player itself must have the user variables. Defining the user variables is completely unnecessary on weapons as they are never stored.
- Weapons may set the user variables on the player via DECORATE or ACS.
- Pickup or Use states both work.
- If the item is solely developed for A_GiveInventory functionality and similar only, defining the user variable first is not needed. Only the receiver needs it defined.
- If the receiver does not have the variable defined, it will log a console message notifying the player it does not exist.
- User defined variables on inventory items will only affect the item itself until picked up; everything afterwards affects only the receiver. As such, if the actor is missing the variable used by CustomInventory, it will also log a message about missing user variables.
- User vars can be stored, but not retrieved, directly through DECORATE. User variables stored through decorate via weapons or custominventory are set upon the owner itself (weapons set on players specifically). ACS must be used upon the calling actor instead.