backIndex

Xelagot action script

Variables: types, declaration, assignement

Variables are used to store and manipulate information: numbers, strings, time, etc. In this scripting language, all variables are global, i.e. they can be accessed and modified everywhere in the script. There are 10 types of variables, each type is characterised by a prefix, followed by one ore more letters. After the first letter, numbers and underscore _ may be used. Each type, except the list, vector and matrix types, has a default set (you do not need to declare this set) which has the prefix and one letter from a to z. In addition to that, the you can declare any number of variables of each type. The types are:

numeric variables - represent both integers (whole numbers) and real numbers

Prefix %

Initial value: 0

Default set: %a, %b, ... %z

Valid custom names: %red, %small_nose, %c5

string variables - represent strings

Prefix $

Initial value: empty string.

Default set: $a, $b, ... $z

Valid custom names: $backdrop, $b1, $simple_av3

date-time variables - They represent both dates and time of the day

Prefix !

Initial value: date and time the script starts running

Default set: !a, !b, ... !z

Valid custom names: !my_bithday, !s, !arrived

location variables - They represent coordinates in AW, as 20.5n 50.3e 10a 90, and they may also indicate a world

Prefix @

Initial value: 0n 0w 0a 0. The degree symbol may be omitted

Default set: @a, @b, ... @z

Valid custom names: @my_place, @s1

person variables - complex location variables, which can be 'cloned' by direct assignment to another person variable. They contain fields for name of an individual person (citizen, tourist or bot), location, world, universe, session number, citizen number, last chatline, and more

Prefix &

Initial value: empty, coordinates as location variables

Default set: &a to &z

Valid custom names: &Speaker_1, &jimmy, &b3

object variables - complex location variables

prefix ~

Initial value: empty, coordinates as location variables

Default set: ~a to ~z

Valid custom names: ~Chair_3, ~floor, ~b3

string lists - customisable string lists, which can be accessed using an index number or a name-value pair. You may load and save them to file

Prefix /s_

Default set: none

Initial value: empty (no strings)

Valid names: /s_Players, /s_menu_1

time-out lists - customisable string lists, holding a name-value pair, which can automatically time out. The name entry is unique - duplicates are not allowed - and works as an index 'number'. The value entry can hold any string. You can specify a time-out value (a date-time value), or set this value to zero to disable timing out. Default time-out value is 60 seconds

Prefix /t_

Default set: none

Initial value: empty (no strings)

Valid names: /t_InRegion, /t_Out_3

packer variables - represent variables

Prefix ^

Initial value: nil.

Default set: ^a, ^b, ... ^z

Valid custom names: ^FirstList, ^b1, ^simple_av3

vector variables - introduced in version 3.416, have 3 elements: x, y, z

Prefix /v_

Default set: none

Initial value: empty (all elements set to 0.0)

Valid names: /v_vecR, /v_myVector_A

matrix variables - introduced in version 3.416, have 16 elements, organised in 4 rows, the last row representing translations.

Prefix /m_

Default set: none

Initial value: identity matrix

Valid names: /v_the_Matrix, /v_Smith_200

VARIABLE DECLARATION

The default set is implicitely declared, and may not be re-declared. All other are custom variables and must be declared before being used. The usual place to declare variables is at the beginning of the script. The declaration consists of the keyword var followed by a comma separated list of variables:

var %small_nose, %c5, $backdrop, $b1, $simple_av3
var %red, @my_place, @s1, !change_backdrop
	

It is legal to use the same name for variables of different types: %hello and $hello may co-exist. Since variables are not case-sensitive, %a is the same as %A.

In the variable declaration, you can initialise some of the variable types if you wish: numeric, string and location variables are in this category. String initialisation here is restricted: the string may not contain commas, and double-quotes will be treated as any other character, leading and trailing spaces will be removed.

var %small_nose = 5.39, %c5 = 7, $backdrop, $b1, $simple_av3 = mickey mouse
var %red, @my_place = 23s 5w 0.1a 230 :mars, @s1
	

This practice is not recommended, except for initialising numerals, because there are some inconsistencies in the notation. It is better to intialise the variables after declaring them.

var %small_nose, %c5, $backdrop, $b1, $simple_av3
var %red, @my_place, @s1
%small_nose = 5.39
%c5 = 7
$simple_av3 = mickey mouse
@my_place = 23s 5w 0.1a 230 mars
	

ASSIGNING VALUES TO VARIABLES

Variables can be assigned values in a variety of ways. Here we will show the direct assignment. Elsewhere we will see assignments as a result of an operation.

Syntax for numbers: %a = x, where x can either be a numeric variable %b or a numeric literal value, a date-time variable !b or a string variable $b. In the case of a date-time variable, the date-time will be stored in the Delphi date-time format, as a 32-bit float. Examples:

var %boing, %lala, %datetime, !thismoment, %buzz
# notice $a is not declared
# it belongs to the default set

%boing = -5.3
%lala = %boing
%datetime = !thismoment
$a = "3"
%buzz = $a
	

See also Numeric variables and operations.

Syntax for strings: $a = x, where x can either be a string variable $b or a string literal of the SDF type, a one-byte character in the form #xxx where xxx represents a number from 0 to 255 (example: #13 for carriage return), a numeral %b (integer), or a variable of the location family @b, &b or ~b (location will be stored without the world). Any string literals containing commas, double-quotes, trailing or leading spaces should be surrounded by double-quotes. Within such a string, double-quotes which are part of the string must be doubled. It is good practise to surround all literal strings with double quotes. In fact, it is very likely that strings without double-quotes will be banished shortly, I haven't yet made up my mind about this.. Examples:

var $pipo, $pepe, $first_planet
var $mercurius, $merc, $CR, $LF

$pipo         = " His name was ""The Bumble Bee"""
$pepe         = $pipo
$first_planet = mercury
$mercurius    = "mercury"
$merc         = """mercury"""
$a = 3.5
$a = "3.5"
$CR = #13
$LF = #10

# store an integer number in a string 
# if %b is 2.1, $a will have '2'
$a = %b

# store a location (no world) in a string
$a = @b
$a = &p
$a = ~m
# results in $a containing a string like
# '25.003n 6.000e 5.00a 270.0'
	

Variable $pipo will be assigned the value His name was "The Bumble Bee", with one leading space.

Variables $first_planet and $mercurius will both contain the string mercury, whereas $merc will have the string "mercury"

See also String variables and operations.

Syntax for location: @a = x, where x can either be a variable of the location family @b, &b or ~b (includes world), a string variable $a or literal containing coordinates usual in AW for teleporting (except for altitude). Altitudes are in metres (not in AW units), coordinates n, s, w, e are in AW units and rotation (or yaw) is in degrees. The degree simbol may be omitted. Any values omitted will be set to zero. You may also specify a world name at the end, preceeded by a colon, or as from xelagot version 3.0, you may omit the colon. Double-quotes " surrounding the literal are not allowed. Examples:

var @Loc1, @Loc2, @Loc3, @Loc4, @Loc5

# a full coordinate specification, no world specified
@loc1 = 50n 300w -0.20a 45.0
@loc1 = 50n 300w -0.20a 45
# note that in AW, this would be written as
# 50n 300w -0.0a 45.0
# because altitudes are expressed in decametres
# and only one decimal place is allowed :(

# this next one sets the world as well to "aw"
@loc2 = 703.002s 25.2e 7.13a 12.5 :aw

# as from xelagot version 3.0, this is also valid (no colon needed)
@loc2 = 703.002s 25.2e 7.13a 12.5 aw


# @loc3 will be equal to @loc2, including the world
@loc3 =  @loc2
# or to the position and world of these variables
@loc3 = &person
@loc3 = ~thing

# loc4 will be at GZ, zero altitude, facing North
@loc4 = 0

# loc5 will be at zero altitude facing North
@loc5 = 200e 7003w

# not valid
@loc5 = "200e 7003w"

# but this is ok
$a = "200e 7003w"
@loc5 = $a

	

See also Location variables and operations

Syntax for date-time: !a = !b. See Date and time variables and operations.

Syntax for person: &a = &b. See Person variables and operations.

Syntax for object: ~a = ~b. See Object variables and operations.

Syntax for vector variables: see Vector variables and operations.

Syntax for matrix variables: see Matrix variables and operations.

Syntax for packer variables: see Using packer variables....


backIndex