SEL Variables and Constants

I plan to expand on this document later more fully.

Simple Variables:

SEL Variables are fairly simple.  You can create any variable and use it as and when you please.  A variable that is not already known is created when it is used e.g.

$myvariable=”Hello”;

Variables are preceeded by a $, e.g. $variablename, and can be made up of letters, numbers and underscores.

There is no typing of variables, you can store a plain number ($myvariable=105;) or a string, or an Array.

Arrays:

Arrays are likewise created as and when they are used, you do not need to pre-declare them.  Any depth of dimension may be created on the fly, e.g.

$myarray[1][2][3]=5;

Assigning an array to another variable automatically converts that variable to a full copy of that Array, e.g.

$myvariable=$myarray;

Will copy all the dimensions of $myarray into $myvariable.

Making your Variables Permanent:

If you wish to keep track of information for more than loading the page once (note this means also reloading the page from an ABML ‘option’ tag will wipe out your variable values), you must use the &permvar function, simply: &permvar $variable1, $variable2, $variable3; (or as many variables you want obviously).  The variables declared like this will remain permanently stored throughout the adventure or until the &killvar function is used on them.

Scoping Variables:

Using complex functions and libraries you can quickly end up with a lot of variables and avoiding a naming conflict can become tricky.  Use the &my scoping operator to make a $variablename only specific to the block it is declared in.  A block can be a function, an ‘if’ clause, ‘while’ loop etc., anything defined with curly braces { }.  The variable declared with &my will only be ‘alive’ inside that block (and any blocks it contains).

Reserved Variables:

At this time there is only 1 reserved variable name, the array @argv is provided.  This currently only holds two elements, $argv[0], which will return the name/number of the abml reference currently being processed (specifically and technically speaking @argv is the command line arguments array, I have simply used the current abml reference as the first cla in this implementation of sel).  $argv[1] holds any data specific to the tag which it was called from for example in tts tags this will be the value of the ref attribute, in tti tags this is the value of the data entered by the user as the reference to turn to.

NULL/Undefined, Zero Values 0 and ‘0’ and Empty String ”

These are significant since Logical operators (AND, OR etc.) and tests (i.e. IF) depend on them.

Firstly, simply note:

0 == ‘0’ == ” == $undefinedvariable

(where $undefinedvariable has not been assigned any value(s) at any time)

All these 4 ‘values’ equate to False when used in a Logical context, eg. if(‘0’){&print “True”;}else{&print “false”;} will display false.

Which leaves us with one small problem:  How do we know which value $myvariable actually holds ‘0’ or 0 or ” undefined?  This is significant e.g. in function parameter passing.

There are two functions to employ to distinguish between these ‘values’.  Firstly, &is_numeric will return true for cases where the variable is 0 or ‘0’ (there is NO way to determine between those two), secondly, &defined will distinguish between a variable that has not been assigned anything at all and a variable that has the empty string ” value (or any other value whatsoever assigned to it, including 0, ‘0’, or ‘cheesecake’)., returning true for any value at all, or false for no value assignation (undefined).

Reference Variables:

Declare a reference using the backslash like so:

$x=5;
$y=\$x;

To obtain the contents of a reference, dereference it like so:

$z=$$y;
&print $z;

… $z will display as the value 5, as it ought.

This may be used in pass-by-reference to functions and you may also use it on array variables as expected. Edit: You may now also reference individual array elements e.g.

$x=(1,2,3,4,5);

$y=\$x[3];

&print $$y;

Will result in output of ‘4’ as expected.

Making a Reference Permanent is pointless, and will not work. Well, It will, only the reference probably wont hold true for the very next instance of a page loading and give you a random value. Probably. I haven’t tested it. I mostly made references for the purposes of pass-by-reference to functions (honest it makes functions much more powerful).

Multiple levels of referencing is not yet supported.

If you don’t understand reference variables don’t worry, most people don’t and seem to live very happy lives. They are genuinely useful though, e.g. they allow you to write functions that change the values of variables passed to them as parameters.

Leave a Reply

Straight outta Blacksand

Skip to toolbar