BlobbieScript - Variables

Traditionally Easyacts only supported pre-set variables of a single character nature. While the most triggers still support these basic preset variables, newer triggers now use more readable named variables. For instance $i traditionally was a variable whose contents were a text pointer to entity for which the script was defined. While this can still be used, the more object oriented nomenclature of @this, or @self is preferred. These can also be written using $ but to break from the past it is suggested that all variables use @ instead of $ (similarly for function $. has been deprecated in favour of %). Additionally, script authors can now declare variables of their own naming on the fly.

0001 @charName = %getName( @self )
0002 @randNum = %getRandom( 1, 500 )

Local and Static Variable

There are currently five types of variables used in the Worlds of Carnage. The first two are types used by BlobbieScript. This style should always be denoted with the '@' marker such as @foo. These types of variables are only known to the script in which they appear, meaning two different scripts, even two different instances of the same script, will see a different value for @foo. As I have said there are two types, script variables can be declared as static, if so their values are remembered from one script instance to the next (and subsequently can be shared by multiple instances of the same script). The programmer needs to take care when declaring static variables since ANY variable in the static expression will become static and can thus block normal script variables.

0001 static @foo
0002 static @foo = @fee = (60 * 60) / 14
0003
0004 Strange Behaviour:
0005
0006 //
0007 // Normal variable.
0008 //
0009 @foo = 3
0010
0011 //
0012 // Static declaration, the original @foo has been clobbered and it's
0013 // value forgotten.
0014 //
0015 static @foo

Entity Variables

Another type of variable is the entity variable. Entity variables can be applied to a rooms, mobiles, or objects. Entity variables can be set using %setEntityVar(), retrieved using %getEntityVar(), and unset using %deleteEntityVar(). These variables are a great way to share information across multiple scripts, especially quest, or game information. For convenience three other functions exist: %setVar(), %getvar(), and %deleteVar(). These are a shorthand for accessing the entity variables of the script owner. For instance:

0001 %setVar( foo, 1 )       is identical to     %setEntityVar( @i, foo, 1 )
0002 %getVar( foo )          is identical to     %getEntityVar( @i, foo )
0003 %deleteVar( foo )       is identical to     %deleteEntityVar( @i, foo )

Another shorter method of accessing entity variables has also been developed using the evars resolution:

0001 @i->evars->foo = 1      is identical to     %setEntityVar( @i, foo, 1 )
0002 @i->evars->foo          is identical to     %getEntityVar( @i, foo )

Persistent Variables

The fourth type of variable is persistent. These variables are saved and can be restored even after a crash. Such variables can be used to ensure an object is unique or to save ownership of some residential portion of the world. There is a multitude of uses for such data. When saving a persistent variable, the variable is shared amongst all entity instances with the same vnum. These variables are manipulated with the following functions:

0001 %setSavedVar()
0002 %getSavedVar()
0003 %deleteSavedVar()

Another shorter method of accessing saved variables has also been developed using the svars resolution:

0001 @i->svars->foo = 1      is identical to     %setSavedVar( @i, foo, 1 )
0002 @i->svars->foo          is identical to     %getSavedVar( @i, foo )

Player Variables

The fifth and final variable type persists in the player's save file. These are known as player vars and can be set for players, objects, and rooms. The following functions are used to manipulate their values:

0001 %setPlayerVar()
0002 %getPlayerVar()
0003 %deletePlayerVar()

Another shorter method of accessing player variables has also been developed using the pvars resolution:

0001 @i->pvars->foo = 1      is identical to     %setPlayerVar( @i, foo, 1 )
0002 @i->pvars->foo          is identical to     %getPlayerVar( @i, foo )

Player vars set on a room are exactly the same as saved vars since rooms can't be saved to player files, but only one instance of a room with a given vnum can ever exist. The following table summarizes the variable types:


Type Set / Get / Delete Persistence
Local @var1 = 1d5
@var1
Unable to Delete
Variable expires when script completes.
Static static @var1 = 1d5
@var1
Unable to delete
Variable and value persist through all invocations of the script for any given boot of the MUD server.
Entity @i->evars->varname
%setEntityVar( )
%getEntityVar( )
%deleteEntityVar( )
Variable and value are set on a given room, mobile, or object and the value persists for any given boot of the MUD server.
Saved @i->svars->varname
%setSavedVar( )
%getSavedVar( )
%deleteSavedVar( )
Variable and value are shared by all homogenous entities with the same vnum and value persists through MUD reboots.
Player @i->pvars->varname
%setPlayerVar( )
%getPlayerVar( )
%deletePlayerVar( )
Variable and value are saved in player files specific to a given player or object instance and persist through MUD reboots.

Predefined Variables

Scripts are fired when events occur. These events can be triggered by a player, a signal, or for a multitude of other reasons. There exists a set of default variables (many cryptic due to backwards compatibility) that are instanciated to facilitate knowledge of what elements played a key part in the firing of the script. These variables are listed below:


Variable Description
@this
@self
@i
A pointer to the owner of the script. Currently this may be a room, character, or object. The @i version was used historically and so has been retained.
@room
A pointer to the room containing the script owner at the time the script is run.
@roomId
The ID of the room containing the script owner at the time the script is run.
@I
The name of the script owner defined by @i. This is set to "something" for rooms and "nothing" for any invalid owners.
@p
Short name of object if the script owner is a character and can see the object defined by @o. If the object is not visible to the owner then it is set to "something". If the owner is not a character then it is set to "nothing".
@P
Short name of target object defined by @t if the script owner defined by @i is a character and can see the object. If the object is not visible to the owner then it is set to "something". If the owner is not a character then it is set to "nothing".
@n
Pointer to the actor that triggered the script. This is usually a character.
@N
The nice'd name of the script actor defined by @n if visible to the script owner. If not visible to the script owner then it is set to "someone". If the script owner is not a character then @n will be considered to be visible. If @n is not a pointer to a character then this will be set to "nobody".
@s
The gender specific possessive for a character script actor defined by @n. This will be one of: his, hers, its. If the actor is not a character then this will be set to "nothing".
@e
The gender specific pronoun for a character script actor defined @by n. This will be one of: he, she, it. If the actor is not a character then this will be set to "nothing".
@m
The gender specific objective for a character script actor defined by @n. This will be one of: him, her, it. If the actor is not a character then this will be set to "nothing".
@h
Pointer to a character being hunted by the character script owner defined by @i. If the owner is not a character then this will be set to "nobody".
@H
The nice'd name of the character defined by @h if visible to the script owner. If not visible to the script owner then it is set to "someone". If the script owner is not a character then this will be set to "nobody".
@t
Pointer to a provided target of the script. In the case of a script triggered by combat, @t will usually be set to the opponent.
@T
The nice'd name of the script target defined by @t if visible to the script owner. If not visible to the script owner then it is set to "someone". If the script owner is not a character then @t will be considered to be visible. If @t is not a pointer to a character then this will be set to "nobody".
@A
Conjunction for a target object as defined by @t. This will have an appropriate value of "a" or "an" (i.e. an apple).
@S
The gender specific possessive for a character script target defined by @n. This will be one of: his, hers, its. If the target is not a character then this will be set to "nothing".
@E
The gender specific pronoun for a character script target defined by @n. This will be one of: he, she, it. If the target is not a character then this will be set to "nothing".
@M
The gender specific objective for a character script target defined by @n. This will be one of: him, her, it. If the target is not a character then this will be set to "nothing".
@a
Conjunction for a the object defined by @o. This will have an appropriate value of "a" or "an" (i.e. an apple).
@o
Pointer to an object that played a part in the script's firing.
@O
Short name of the object defined by @o if the character owner defined by @i can see the object or the owner is not a character. If the script owner is a character and cannot see the object then this is set to "something". If the object defined by @o is not valid then this is set to "nothing".
@x
An arbitrary string that may be set by whatever triggers the script. The prupose of this value is highly dependent on the script. For instance the catch death act populates @x with the name of the creature that died since the creature itself cannot be accessed.
@X
The first word of the string defined by @x.
@q
Pointer to a random object in the current room if any exist.
@Q
Short name of the object defined by @q if the character owner defined by @i can see the object or the owner is not a character. If the script owner is a character and cannot see the object then this is set to "something". If the object defined by @q is not valid then this is set to "nothing".
@r
Pointer to a random creature in the current room if any exist.
@R
The nice'd name of the random character defined by @r if visible to the script owner. If not visible to the script owner then it is set to "someone". If the script owner is not a character then @r will be considered to be visible. If @r is not a pointer to a character then this will be set to "nobody".