SEL Variables and Constants

I plan to expand on this document later more fully.

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.


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 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.


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


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 tthroughout 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).

Leave a Reply

An online project to bring the worlds of Fighting Fantasy, Lone Wolf, Choose Your Own Adventure and other Gamebooks to life

Skip to toolbar