BlobbieScript - Expressions

Previously the Easyact engine supported some simple block control mechanisms. Some of the mechanisms worked well, others not so well. The 'if' statement is a good example for one that generally works well. One of the greatest drawbacks of the 'if' statement though, is its lack of support for joining conditional expressions. This is solved in the new engine. The following control blocks are supported by BlobbieScript:

Keyword Description
static Initialize static variables
if Test for conditional block entry
elseif Test for conditional block entry where priors have failed
else When all prior tests fail then enter this block
endif Close a series of conditionals
for Initialize and loop over some expression while it evaluates to true.
endfor Loop back to beginning of the matching for block.
foreach Iterate over an array's values.
endforeach Loop back to beginning of the matching foreach block.
do Enter a looping block
dowhile Test conditional for re-entry into 'do' block
while Test conditional for entry into block
endwhile Loop back to beginning of a 'while' conditional loop
switch Select the first matching case and continue evaluation from that point.
case A conditional starting point based on the case value matching the switch value.
default If all case statements for the switch block fail, then evaluation will continue at the default statement.
endswitch Marker for the end of a switch block.
wait Wait for a number of time units (secs, hsecs, qsecs, tsecs)
protect Run code in block to completion
endprotect Marker for end of protected block
break Break out of innermost loop or switch statement; if none then return
continue Jump to beginning of looping block immediately
label Set a marker for a 'jumpto' statement
jumpto Jumpto a given labelled point in the script
return Exit script optionally providing a return value
retval Return a value but do not exit script
null The special null value / datatype.
true Boolean true value.
false Boolean false value.
<< The final evaluation of the whole line is fed into the mud's interpreter as though the script owner had issued it as a command.
\ Indicates line continues or is a continuation
{ or } A line containing only these and spaces is ignored

Expression Evaluation

One of the biggest problems in creating the BlobbieScript engine was to try and add in real language support while adding the flexibility of evaluating expressions as can be done in almost any other programming language. To maximize ease and backward compatibility there exist two modes of expression evaluation: pure and impure.

Pure expressions are any expressions that are part of a block control expression or part of a function's parameter part. These are called pure because they do not require special treatment to be evaluated in their context. To illustrate, the following is now possible:

0001 if( %getLevel( $n ) < 50 and !%getRandom( 1, 10 ) )
0002 {
0003    damage $n %( (1d10 + 1) * 3 )
0004 }
0005 else-
0006 if( %getAlign( $n ) / 10 > 60 or %getAlign( $n ) < -60 )
0007 {
0008    damage $n %( 1d(1d10) )
0009 }
0010 endif

The difference between pure and impure expressions is also illustrated above. Notice to get the power of expression evaluation within a non- block control statement the expression needs to be evaluated with the special %() function. This is because for backward compatibility reasons the new engine guesses that anything in a block control statement is any of variable, function, or string. Given this interpretation all tokens extracted are considered to be implicitly joined by an invisible concatenation operator. Since this may become confusing if a variable is used that blends into an actual word the following can be used to ensure the end of the variable:

0001 @name = %getName( $n )
0002 echoto r all @{name}'s mother is a wench!

The advantage of such expression evaluation is that it gets rid of the old system of $.calc( 1, +, 3 ) since this can be expressed as %( 1 + 3 ). Moreover the engine fully supports integers, floats, strings, and associative arrays (AKA: dictionary, string indexed array, hash).

Other Types of Expressions

In addition to block control expressions and normal expressions there are comments, continuations, and block tags. Comments begin when a pair of forward slashes "//" are encountered and end at the end of the line.

0001 Example:
0003 //
0004 // Get a list of creatures in the room.
0005 //
0006 @list = %roomGetMobs()     // Creatures are stored in @list
0008 *
0009 * This is a deprecated style, and only works when
0010 * the "*" is the first non-whitespace character on
0011 * a line.
0012 *

The \ at the beginning of a line denotes that the expression continues from the previous line. This was added so conditionals can be nicely formatted for easy reading.

0001 Example:
0003 echoto room all
0004 \   You can feel the rush of winds building in strength to
0005 \   a deafening roar. You clasp your ears to mitigate the
0006 \   painful effects of the sound.

Block control tags are more for aesthetic purposes. I come from programming background which uses braces to denote code blocks. Normally BlobbieScript doesn't support these blocks due to backwards compatibility; however, for the sake of good looking code (IMHO) any line containing only a sequence of "{" or "}" characters will be ignored.

0001 Example:
0003 if( @n->name == "The Overlord" )
0004 {
0005    echoto notc @n Grovel before your master heathens!
0006 }
0007 else
0008 {{{{
0009    spit @n
0010 }}}}
0011 endif

Finally a semi-colon is permitted on most pure expressions where one would make sense. The behaviour of the engine is to strip it if it is the last character on the line. Note that commands normally passed on to the game's command interpreter will retain any trailing semi-colons.

0001 Example:
0003 @i = 20;
0004 while( (@i -= 1) > 0 )
0005 {
0006    echoto room all A fireball suddenly explodes before you.
0007    damage room all %( 20 + 1d15 ) fire
0009    wait 20 secs;
0010 }
0011 endwhile;