### MudMagic BASIC Scripting

When you create a Trigger or Alias, you can select some scripting language support. This document describes the usage of the MudMagic BASIC scripting engine.

MudMagic BASIC scripting follows the normal BASIC style, that is:

    IF ... THEN
    ELSE
      ....
    END

For Example:

    IF $1 = "Somevalue" THEN
        print "say You said $1"
    ELSE
        print "say You said something else"
    END

### Basic commands available

There are certain commands available in the scripting engine. Below is an index outline.

Expressions

An expression is something that applies two values togeather. To check is value FOO is equal to value BAR, you'd use FOO = BAR

    	For numerical operands: + - / * = < > <= => <>
    	For string operands: + = <>

Commands

All lines within a script are considered to be a command entry to the scripting engine. Blank lines are ignored.

    		REM commentary, this is ignored - so you can put notes to yourself here

    		PRINT strings, expression
    		SEND  strings, expression (print and send are identical)
    			if two tokens separated by ',' - space will be insert
    			if two tokens separated by ';' - tab will be insert
    			if two tokens seperated by '.' - no spacing occurs
    			if PRINT ended by ',' or ';', "new line symbol" will not be inserted after last token
    			into strings in PRINT command external variables may be appears

    			examples:
    			print "this","is","a","test";
    			outputs: This is a test

    			print "this";"is";"a";"test";
    			outputs: This	is	a	test

    			print "This"."is"."a"."test";
    			outputs:  Thisisatest

    		IF condition THEN
    		 ...
    		ELSE
    		 ...
    		END

External variables

An external variables are read in with the $ symbol. You can pass external variables to your script with regular expression.

Name starts by '$'.
For example. To capture 2 variables in the statement: test one two. You could write a regular expression such as:
^test (.*) (.*)

This will match any sentence you input in the command line that starts with the word test, and catches the first two words after test. You can then use:

FIRST_WORD = $1
SECOND_WORD = $2
in your script.

External functions

External functions are special MudMagic functions which interact with the client. There is currently only 1 MudMagic external function to date.

    		Name starts by '$'.

    		$MESSAGEBOX "Message to output"

### BASIC script flow

---------------------------------- There are numerous methods of writing your scripts. You can use multiple IF .. THEN .. ELSE statements, or you could end each IF check in order. Trial and error will be your guide. For example:

    NUMBER_ONE = 10
    NUMBER_TWO = 20

    IF NUMBER_ONE > 5 THEN
    	PRINT "Number one " NUMBER_ONE;
    ELSE
    	IF NUMBER_TWO < 100
    		print "Number two is less than 100"
    	ELSE
    		print "Number two is " NUMBER_TWO
    	END
    END

The important thing to remember is to close your checks in sequential order. If not, you will receive syntax errors when your script executes.

### Variable usage and creation

Variables in the client are assigned locally and through regular expression. A variable can be either a string value, or numerical value; and are treated accordingly. If a variable contains only digits - it is considered a numerical variable and can process mathmatical equations. Please review the examples below for the scope of variable usage.

### BASIC Examples

You can test the following scripts out with the Tools -> Script Testing window. For more details on this window, see the Scripting, Testing link in the left frame.

1.

    N1 = 25
    N2 = 35
    NUMB = ((N1 + N2) * 5) / 25
    PRINT NUMB;
    PRINT "Hello"; ","; "World";
    PRINT "The number is -"; NUMB;
    PRINT NUMB; "- is the number"; 700;

2.

    N1 = 45
    N2 = 35

    IF N1 < N2 THEN
    	PRINT "THEN 1 PART"
    	PRINT "N1 ="; N1
    ELSE
    	PRINT "ELSE 1 PART"
    	PRINT "N2 ="; N2
    END

    PRINT "AFTER IF"
    PRINT "N1 ="; N1
    PRINT "N2 ="; N2

3. This takes an external pcre caught command. Example: Alias: ^test (.*)

    PRINT ": EXT $1"
    rem $MESSAGEBOX0
    rem $MESSAGEBOX1 "Test"
    rem $MESSAGEBOX2 "First arg","Second arg"

4.

    IF $1 = "Kyndig"
    THEN
      print "yup, was kyndig"
    ELSE
     print "nope, wasn't kyndig"
    END

Copyright © 2004-02-26 MudMagic.Com