WSL

Warlock Scripting Language
We call it WSL for Wizard Scripting Language or Warlock Scripting Language. It's left purposefully ambiguous and could just as easily be Stormfront Scripting Language, but SSL is already taken.

Overview
Our scripting language is based very closely on the language from the Wizard and from StormFront, with some additions from other sources. (Add more stuff here)

Basics
In computing, regular expressions, also referred to as regex or regexp, provide a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification. Warlock is just such a program, this link will provide you with a tool to assist you in understanding and using regex's!

Commands
Most lines consist of a single command with some argument(s). Ex. or

Commands are not case sensitive, and they can contain variables. Ex. setVariable type re setVariable exp /matches\s*a\s*(\w+)/ setVariable number /-?(\d+)(\.\d+)?/ match%type wordLabel %exp match%type numberLabel %number matchwait

Variables
You can use variables within any line. Variables start with "%" or "$", such as "%foo" or they are enclosed in them such as "%foo%". Always use the latter form when you want to give some text or concatenate variables, such as "%foo%World.". If "%foo" is set to "Hello," that would result in "Hello,World." Ex. setVariable target World setVariable var target echo Hello, %target%. echo Hello, %(%var). Both would display "Hello, World."

Variables can contain any characters. The first form given above ends the variable name on "%", "$", whitespace, "(", and ")". The second form can contain those characters, but "(", and ")" must be escaped with a backslash. We recommend only using A-Z, a-z, 0-9, and _, but for compatibility we allow symbols as well.

Concatenating variables: Sooner or later you’re going to want to do this and understanding the value as well as how to do it is important. With WSL there is no way to build an array, however you can build a poor mans array with inventive use of the “counter” and the concatenation of variables!

Suppose you want to cycle through a list and act on every item in the list? This example will demonstrate the concept.

Labels
You can start any line with a name follow by a ":" to label that line. On any like preceding or following that line, you can "goto" that line. Ex. goto myLabel echo No!!

myLabel: echo I hope you find this example useful

The first line will cause the execution of the script to jump to the 3rd line "myLabel:" and the execution will continue with the echo.

Labels may contain any character other than ':' (colon). To keep anyone who looks at your script from getting a headache though, please try and stick to letters, numbers, and underscores. Although labels can contain % and $, they wont dereference variables. So if you had a variable "box" with the value "thing" and a label "%box:", the label wont evaluate to "thing". You can still use variables in gotos, or matches however and they will be dereferenced before the lookup.

Functions
Functions are very much like labels. They are defined by labels, but instead of using "goto" to jump to them, you use "gosub". "gosub" can be passed any number of arguments, which will be stored in "$1", "$2", etc with the entire list being stored in "$0". "return" brings execution back to the command after you called the function. Ex. gosub printHello World echo Good-bye exit

printHello: echo Hello, $1$. return

The result of this would be "Hello, World." followed by "Good-bye".

IMPORTANT See NOTE under Matchre

Local Variables
Variables that start with "$" are treated as local variables. Any local variables you create or change only have effect within the local scope. The scope is defined to be within the current function. (More about functions later.) Ex. setLocalVariable 1 foo gosub testing bar echo The value in 1 is $1 exit testing: echo The value in 1 is $1 return

They output of this sequence would be "The value in 1 is bar" followed by "The value in 1 is foo".

Conditionals
Sometimes you need to know whether a condition is true before deciding what to do. The if/then/else construct allows you to do this. It's done in the form:. Any subsequent command starting with "else" will be executed on if the "if" condition evaluates to false. Ex. if %roomplayers contains "Eanur" then put say Hello, Eanur else put say I really wish Eanur were here.

Actions
Actions are commands that are execute whenever their text matches the output from the server. They are given in the form: action when. You can remove an action with "action remove " and remove all actions with "action clear". Ex. action gosub sayHello when hello action gosub sayGoodbye when good-bye

waitfor quit

sayHello: action remove hello put say Hello. return

sayGoodbye: action remove good-bye put say Good-bye. return

NOTE: My experience with Warlock informs me that using gosub or goto from an action command is not a 100% proposition. I’m not versed in the engines code and I can't tell you why technically. I have used WSL scripts since July of 2008. The script above will always work, it’s sitting there doing nothing but waiting until it sees “quit”. However if you are trying to say “hello” when someone or some thing (theres a difference) says it and your in the middle of juggling or some other activity I would suggest the following…

SetVariable JUGGLIES balls SetVariable HELLO FALSE SetVariable GOODBYE FALSE

action SetVariable HELLO TRUE when says, hello action SetVariable GOODBYE TRUE when says, good-bye

GoTo JUGGLE

JUGGLEW: Pause JUGGLE: Match NO-BALLS referring to Match TALK-RESET roundtime Matchre JUGGLEW /^Sorry,|\.\.\.wait/i put juggle my %JUGGLIES If %HELLO = “TRUE” then instant put say Hello If %GOODBYE = “TRUE” then instant put say Good-bye MatchWait

TALK-RESET: SetVariable HELLO FALSE SetVariable GOODBYE FALSE GoTo JUGGLE

NO-BALLS: ECHO You have no %JUGGLIES to juggle with! Exit

action
Executes  whenever text matched by   is received.

Removes the action with the text.

Removes all of the actions.

counter
The operand for  is always %c.

Operators:


 * set - Sets the operand to the argument. Ex.  Results in
 * add - Adds the argument to the operand. Ex.  Results in
 * subtract - Subracts the argument from the operand. Ex.  Results in
 * multiply - Multiplies the operand by the argument. Ex.  Results in
 * divide - Divides the operand by the argument. Ex.  Results in
 * modulus - Divides the operand by the argument, and stores the remainer in the operand. Ex.  Results in
 * log - Takes the log with the base provided by the argument (default 10) or the operand.
 * ln - Takes the natural log of the operand.

SUB_RUNTIME: Counter set %t Counter divide 60 SetVariable RUNTIME %c ECHO ***************************** ECHO Running for %RUNTIME% minutes. ECHO ***************************** Return

Also see; (Math handles operations on user created variables)

debug
Echos varying levels of your script to screen starting with just setvariables and going up to every line executed. Use with caution, screen scroll becomes horrific in larger scripts!

delay
Adds a delay of  to the end of every roundtime before continuing on with the next command. Can be a fraction of a second as in. '''As of sometime in Feb 2013 this appears to be bugged, will stall the script if used. '''

deleteVariable
removes the value stored in.

Caveat: As of the time of this writing it has no impact on the value stored on the server.

echo
prints the text to the screen.

else
executes  if the last if condition was false.

Caveat: else cannot contain an action or another if at the time of this writing.

exit
stops the currently running script.

getcomponent
returns the text of the exp requested as seen in the field experience window to

is the full name as seen when you input exp all.

SetVariable EXP2CHECK Mechanical Lore GetComponent EXPVALUE exp %EXP2CHECK If %EXPVALUE > 0 then Echo EXPVALUE = >>>%EXPVALUE%<<< If %EXPVALUE < 1 then Echo You're not learning any %EXP2CHECK Exit

In the above example you get back something like;

EXP2CHECK = >>>    Mechanical Lore:  567 44% intrigued   <<<< Note the inclusion of the spaces on the front and back of the text string.

OR

You're not learning any Mechanical Lore

This sub routine, SUB_GET-EXP-VALUE will return a numerical value of the experince you request to a variable of your choice. This is the number you see that proceeds /34 when you input the DR exp command. Instructions are commented in the code.

getstatus
saves the status (true or false) to

saves the status (true or false) to

StatusType's = bleeding | dead | hidden | invisible | joined | kneeling | prone | sitting | standing | stunned | webbed

GetStatus standing Echo standing = %standing GetStatus AM_I_SITTING sitting Echo AM_I_SITTING = %AM_I_SITTING exit

gettime
Saves the number of 10ths of a second from the start of January 1, 1970 to

EG: GetTime CURRENTTIME1 pause 10 GetTime CURRENTTIME2 math CURRENTTIME2 subtract %CURRENTTIME1 ECHO %CURRENTTIME2 exit This should return 100 or very close to it.

getvital
saves the vital value to 

saves the vital value to

Vital Name's = health | mana | stamina | spirit | concentration

GetVital health Echo health = %health GetVital MYHEALTH health Echo MYHEALTH = %MYHEALTH GetVital mana Echo mana = %mana GetVital MYMANA mana Echo MYMANA = %MYMANA GetVital stamina Echo stamina = %stamina GetVital MYSTAMINA stamina Echo MYSTAMINA = %MYSTAMINA GetVital spirit Echo spirit = %spirit GetVital MYSPIRIT spirit Echo MYSPIRIT = %MYSPIRIT GetVital concentration Echo spirit = %concentration GetVital MYCONCENTRATION concentration Echo MYCONCENTRATION = %MYCONCENTRATION exit

gosub
goes to the  and stores the first argument in , the second in  , etc, and the entire list in.

If you want to pass multi word variables enclose them in quotes.

EG; GoSub SUB_TEST oneword "two words" "three long words" anotherword Exit

SUB_TEST: ECHO $0 ECHO $1 ECHO $2 ECHO $3 ECHO $4 return

$0 = oneword "two words" "three long words" anotherword $1 = oneword $2 = two words $3 = three long words $4 = anotherword

When the function returns, all local variables are reverted to the values they contained before the.

Example:Multi-Nested GoSub

goto
moves execution to.

if
executes the  only when   is true.

can be: If NOT - Here are some examples of using not. SetVariable WEAPON broadsword SetVariable WIELD-STR wield my %WEAPON If (%WIELD-STR containsre "(left|LEFT)" && %lhand contains %WEAPON) || (not (%WIELD-STR containsre "(left|LEFT)") && %rhand contains %WEAPON) then GoSub SUB_ECHO1 else ECHO You have a %WEAPON in your right hand. exit
 * - is true when both values are equivalent. Ex.  Alias: ==
 * - is true when both values are not equivalent. Ex.  Alias: !=
 * - is true when the first value is greater than the second value. Ex.
 * - is true when the first value is greater than or equal to the second value. Ex.
 * - is true when the first value is less than the second value. Ex.
 * - is true when the first value is less than or equal to the second value. Ex.
 * - is true when either condition is true. Ex.  Alias: or
 * - is true when both conditions are true. Ex.  Alias: and
 * - is true when the second string is a substring of the first string. Ex.  Alias: indexof
 * - is true when the second string is a substring of the first string as expressed in a regular expression.
 * - is true when value is false. Ex.  Alias: not
 * - is true when the variable exists. Ex.

SUB_ECHO1: ECHO Your right hand does not contain %WEAPON return

if_#
-  execute   if the variable associated with that number,   -   is set.

instant
This will bypass the normal checks on a command, so that it can happen during RT.

instant put I don't care if this happens during RT

match
Sets some text to match output against for the next. When there is a match, execution is restarted at. Ex. match rt Roundtime match error referring put juggle balls matchwait

rt: waitRoundTime echo Done juggling. exit

error: exit

matchre
This follows very closely to, except rather than matching with text, it matches with a regular expression. For constructing regular expressions, please see Java Patterns. They must be given in the form:  with an optional trailing i for case insensitive patterns. You may find downloading and useing this tool of high value in attempting to understand and trouble shoot regular expressions.

The matched groups from regular expressions are stored in the variables $0, $1, etc. $0 is the entire match, $1 is the first group, etc. See the page on Java Patterns for more information about groups.

NOTE Take care when using capture groups in actions, you can inadvertently pass that capture to a sub. To avoid this you can specify a non-capture with this sytax:

action SetVariable MINDSTATE LOCKED when Overall state of mind:\s+(?:very murky|thick|very thick|dense|very dense) action SetVariable MINDSTATE CLEAR when Overall state of mind:\s+(?:clear|fluid|murky)

The "?:" keeps the string inside the parens from becoming the local variable $1

Practical example of regular expression matching;

Example assumes you've set the variable DIR2GO in previous code MOVE2NEW-ROOMW: Pause MOVE2NEW-ROOM: Matchre CRITTERLOOKCOUNT /need to disengage first|You are engaged/i Matchre MOVE-OCCUPIED /also here|CAUTION: SNIPERS|alfar avenger/i Matchre MOVE-CLEANUP /Obvious\s(?:paths|exits)/i Matchre MOVE2NEW-ROOMW /^Sorry,|\.\.\.wait/i put %DIR2GO MatchWait 5 ECHO Match Failed MOVE2NEW-ROOM: GoTo GET-MOVE-DIR

matchwait
waits until one of the es matches some text. An optional argument of timeout will force the matchwait to stop waiting after the given number of seconds and continue execution.

math
is identical to, except the result is stored in   rather than.

SUB_CALCRUNTIME: SetVariable TIMENUM %t SetVariable NUMINT %TIMENUM SetVariable NUM %TIMENUM Math NUM Modulus 60 Setvariable CNTSEC %NUM Math NUMINT subtract %NUM Math NUMINT divide 60 SetVariable CNTMIN %NUMINT Pause ECHO ********************************************** ECHO Running for %CNTMIN% minutes, %CNTSEC seconds. ECHO ********************************************** Return

This ones a little easier to digest maybe...

SetVariable CRITTER-COUNT %monstercount SetVariable DEAD-NUM 0 ECHO roomobjects = %roomobjects If %roomobjects contains "appears dead" then SetVariable DEAD-NUM 1 ECHO DEAD-NUM = %DEAD-NUM Math CRITTER-COUNT subtract %DEAD-NUM ECHO CRITTER-COUNT = %CRITTER-COUNT DeleteVariable DEAD-NUM If %CRITTER-COUNT < 1 then return Else put retreat return

move
is equivalent to  followed by.

A practical note on moving around in DR via script.

Experience has shown me that  will sometimes fail when round time occurs, the brook you cross in the NW section of Goblins/Hogs West of the Crossing is a good example. To avoid stalling out you may want to consider the following sub routine and or some derivation of it for those instances. MAIN-SCRIPT: move e GoSub SUB_SWIM e move e Exit

SUB_SWIM: SetVariable SWIM-DIR $1 GoTo SWIM-MOVE

SWIM-MOVEW: Pause SWIM-MOVE: Matchre SUB_RETURN /Obvious\s(?:paths|exits)/i Matchre SWIM-MOVEW /^Sorry,|\.\.\.wait/i put %SWIM-DIR MatchWait 15 ECHO Failed Match SWIM-MOVE: Exit

SUB_RETURN: return

nextroom
waits for a signal the your character has moved into a new room.

pause
waits the specified period of time, and then continues waiting until the current roundtime has expired. is an optional parameter and if omitted,  waits for 1 second.

playsound
plays a sound file contained in the same directory as the script. Types of sound files supported depends on platform. WAV's are usually the best bet.

put
sends  to the server.

caveat: If you "put .scriptname", it will run the script "scriptname" and exit the current running script. This is for backwards compatibility with how stormfront does things. If you want to run the scripts concurrently, see the Run command.

random
sets  to a random value between   and   inclusive.

return
takes execution back to where it was before the function was called. The state of local variables is returned to what it was before the function was called.

run
will attempt to run  as a script. It is similar to using  except run will leave the current script active whereas using put would cancel the current running script in favor for the new one.

save
stores  into.

setLocalVariable
Exactly the same as setVariable, except works on local variables rather than global variables.

setVariable
stores  into.

Caveat: As of the time this was written, we did not store variables on the server.

shift
removes the first argument and moves all of the others down one place. becomes, etc.

does the same thing to $1, $2, etc. instead of %1, %2, etc.

timer
uses  to keep track of elapsed time, unless a variable is specified. begins/resumes the timer. pauses the timer. resets the timer to 0.

wait
halts execution until a prompt is received.

waitfor
halts execution until  is received.

waitforre
is identical to  except it takes a regular expression and the groups are stored like.

Predefined Variables

 * %t - variable used by the timer
 * %c - variable used by
 * %s - variable modified by
 * %r - variable modified by
 * %rt - time remaining on the roundtime
 * %roundtime - alias to %rt
 * %monstercount - contains the number of monster-bold things in the room, that includes monsters, familiars, dead monsters, alfar avengers, etc. You must have monsterBold set for this to work. If it's not set, this will always be 0.
 * %rhand - contents of the right hand (returns "Empty" if nothing in hand)
 * %lhand - contents of the left hand (returns "Empty" if nothing in hand)
 * %spell - spell currently being prepared (returns "None" if no spell is being prepared)
 * %roomdesc - description of current room (maybe room last looked at)
 * %roomexits - room exits
 * %roomplayers - uh, players in the room (the expression [If %roomplayers = " "] is true if there are no players visible in the room)
 * %roomobjects - you know... stuff on the ground and also critters in the room.
 * %roomtitle - As of 3/11/10 if the room title is [Crossing Bank] this will return (without the quotes) "Room - Crossing Bank"
 * %lastcommand - The last command sent to the server
 * %character - The named of the current character you're playing.

[Mistwood Forest, Treetop] From your vantage point you can see a stone road below. To the east, as the forest thins, the branches become less dense and tangled. A series of blue rags, tied to branches, marks a route through the thinning forest canopy to the east. The trunk of one tree is scratched on one side, as if it has been used frequently to climb between the ground and the treetops. You also see some silver coins, some bronze coins, some copper coins, a gold-taloned elder forest gryphon that is flying around, a scruffy leopard that is sitting, a fiery fissure and some junk. Also here: Bogus who is surrounded by an opalescent cobalt blue ethereal shield. Obvious paths: east, southeast, southwest, west, northwest. [script started: 1] [1]: *************************************** [1]: Title = Room - Mistwood Forest, Treetop [1]: *************************************** [1]: roomdesc = From your vantage point you can see a stone road below. To the east, as the forest thins, the branches become less dense and tangled. A series of blue rags, tied to branches, marks a route through the thinning forest canopy to the east. The trunk of one tree is scratched on one side, as if it has been used frequently to climb between the ground and the treetops. [1]: *************************************** [1]: roomobjects = You also see some silver coins, some bronze coins, some copper coins, a gold-taloned elder forest gryphon that is flying around, a yelith root, a bishop arrowhead, a scruffy leopard that is sitting and a fiery fissure. [1]: *************************************** [1]: roomplayers = Also here: Bogus [1]: *************************************** [1]: roomexits = Obvious paths: east, southeast, southwest, west, northwest [1]: *************************************** [script stopped: 1]