Variables and References

Return to Online Manual Contents

Variables are named values.  Variables are initially defined with the DECLARE command.  Variables may be part of an object, or may exist only temporarily.  While a macro is being executed, DECLARE will create new variables in the macro's space.  If no macro is being run, or if the variable previously exists on an object, the value is set on the current active object.

A variable may be referenced by putting a % before the name.  Almost(all) places that expect any other word will also accept variable references. 

A macro may be defined to have parameters, these parameter names are also valid variable names.  DO NOT use declare to change the value of a variable passed as a macro argument.  Macro parameters may also be referenced numerically, ie in the following example %0 and %1 are also valid variable references.

/macro test one two
/echo %two %one
/test this reverse
reverse this

/VARS will list the currently defined variables on an object, and if executed within a macro, will also list the variables avaiable in the current macro context.

/declare greeting Hello
/declare user you
/echo %greeting %user.
'Hello you.'

/decl a var1
/decl b var2
/decl %a bacon
/decl %b sandwitch
/echo %var1 %var2
bacon sandwich

Var1 and Var2 were never declared. This would normally cause error messages to be displayed, and the remainder of the line, or the variable references, or some nearly undefined result will result... however, by referencing the value of a (var1) in a declare (/declare %a value) the variable is defined...

Variables may be referenced from another object. The format of this reference is %object.var.  Variables may also be declared and updated in other objects.  /DECLARE in Ojbect VarName Value - creates a variable called VarName with the specified value IN and object.

/create obj
/decl in obj user Bob Smith
/decl in obj pass Password
/echo %obj.user, %obj.pass
Bob Smith, Password

Multiple objects which have the same name may be reference by puttig a count front of the name... 1.obj, 2.obj, 3.obj, etc. If a variable is to be gotten from an object which is not the first, then it's name must be bounded by parentheses. If the name of an object is a variable, it must be bounded by parentheses. If a varible from an object within an object is to be referenced, the objects may be put together.... The only part of this which cannot be a variable is the variable name itself

/create obj obj obj obj
/decl in 1.obj name Bob
/decl in 2.obj name Joe
/decl in 3.obj name Tim
/decl in 3.obj name Tom
/echo /echo %(2.obj).name /echo %(2.obj).subobject.var /echo %obj.subobject.subsubobject.var /echo %(%objvar)(%subobjvar).var

Builtin Variables

There are several variables which are always available... and are often updated to new values.

%now - contains the current time (hh:mm:ss)
%time - contains the current date and time (mm/dd/yyyy hh:mm:ss)
%me - is the name of the object
%room - is the name of the object the object is in.
%eol - an end of line (carriage return or newline)
%blank - is a single space character.
%contents - this is the contents of the current object

Some discussion of the variable prompt is in order. The prompt variable is created with a sentience. The initial value is "[%room/%me]:". The user may /declare prompt to be something else. During the declaration, variables are dereferenced once. What does that mean? That means the one attempt to resolve the value of a variable is done before storing the new value.

/declare prompt %now: This is invalid, and will set the prompt to the current time, and will not change. Why? Because the variable 'now' was evaluated, and it's value was stored in the variable 'prompt'. /declare prompt %%now: This will work as expected. The current time will be shown as the prompt. The doulbe '%%' are reduced to a single '%' and '%now' is stored in the variable 'prompt'.

Another good idea is to "/declare save %prompt" and later "/declare prompt %save" this will retain the value specifically in prompt. The default connect script now replaces the prompt with %%eol while connected to a server, and restores the prompt when disconnected. To restore the prompt to the original declaration is "/declare prompt [%%room/%%me]:" note: the prompt is built with [%room/%me].

Extended Variables

Some objects will have dynamic variables which can be set/read. For example a 'cards' hand object will have %hand, %cards, %pokerhand, %pokervalue. These variables come from code which executes instead of being statically set by macros and other internal commands.