Scripting for the Wizard FE
From Haelrahv Wiki
The Wizard allows you to script actions with two types of script files. The first type, which has a ".Wiz" filename extension, is always executed from the Wizard's "Scripts/Execute a Script" menu selection. The second type, which has the ".Cmd" filename extension, is invoked from the Wizard's "command line" area (ie: the text input box). The difference between these two types of scripts is that "command" scripts can take parameters from the command line, just like DOS batch files.
The parameters are accessed as %0 (the entire line) through %9. In normal usage, you'll only use %1 through %9. So, if you typed the following into Wizard's text input area:
.find jim joe bob stacy kim
in your script %1 would be replaced with "jim", %2 with "joe", %3 with "bob", %4 with "stacy", and %5 with "kim". A discussion of easy ways to loop through these command parameters is in the following section, which lists all of the available scripting commands:
Contents |
put <text>
The PUT command is used to send commands to the game. Example:
put get sword from my backpack put remove my shield put 'Off to battle!
echo <text>
The echo command is used to display text in the Wizard's game window. This text does NOT get sent to the game; it's simply there for you to display a message to yourself. For example:
echo Starting up so-and-so script.
Note: echo with no string after it will simply display an empty line.
if_0 through if_9
These commands allow you to check for the presence of a command line parameter. For example, let's say you write a script named HEAL that expects a name to be present on the command line. You could accomplish this with the following code:
if_1 goto nameThere echo Usage is HEAL <player name> exit
nameThere: do your stuff here to heal them.
Note: if_0 is the entire command line.
NextRoom
The NextRoom command pauses until a room description is received (that is, the user moved to a new room). For example:
put north NextRoom
Move <direction>
The Move command is similar to a PUT command, except it automatically does a "NextRoom" command for you. In other words, these two code fragments will do exactly the same thing:
1) put north nextroom
2) move north
Wait
WaitFor <text>
These commands allow you to pause the script, waiting for data to be returned to you from the game. WAIT does a pause until a new command prompt is received:
put get sword from my backpack wait put remove my shield
Note: it is important to remember that it is sometimes possible for the game to give you another prompt WITHOUT that prompt being a result of your last action (ie: someone enters the room, etc).
The WAITFOR command waits for the string you specify to come back to you. This is the PREFERRED way to make sure that your command has been accepted and processed by the game. The WaitFor command works with both a "partial" string specified, or a "full" string, as seen in this example:
put prep 401 waitfor Your spell put cast put prep 406 waitfor Your spell is ready. put cast
goto <label>
The GOTO command is what you use to branch to a different place in the script. You must specify a label to go to, and that label must be defined elsewhere, on a line by itself and with a ':' at the end of it:
..do something here.. goto NextLabel ...code... NextLabel: ...code...
Note: you may jump to a label in either direction; that is, below or above the current execution point in the script.
pause <amount>
The PAUSE command pauses the script for the number of seconds specified.
exit
The EXIT command ends the current script immediately.
save
The SAVE command saves the specified parameter (ie: %1 through %9) into a variable that can be used at any time in the script. This is normally only needed in scripts where you are looping through the command line parameters (see the "shift" example below)
Shift
The SHIFT command shifts the command line parameters to the left. For example, let's say you entered the following to run the HEAL.CMD file:
.HEAL name1 name2 name3
Initially, the parameter %1 would be "name1", %2 would be "name2", and %3 would be "name3".
After one SHIFT command, the parameter %1 would be "name2", and %2 would be "name3" (%3 would be non-existant). The power of this is that you can "loop through" all of the parameters passed on the command line, operating on them one at a time. As an example, let's create a SELL.CMD file that gets all of the items specified out of your backpack and sells them, as in:
.sell gem gem armor sapphire diamond
SELL.CMD: MainLoop: ; first, see if we have a %1 name to work on. ; If not, we're done so we just exit. if_1 goto doIt exit doIt: put get %1 from my backpack waitfor You remove put sell %1 waitfor hands you ; Now, shift the parms to get the next name on the line Shift goto MainLoop
The SAVE command (mentioned above) is also useful for saving a parameter that you want to apply to all of the other parameters. For example, let's write a DO.CMD file that has the following syntax:
.do <what to do> <player1> <player2> .... <player n>
which you could invoke with a command line like this to wave to four players you see in your room:
.do wave Kodos Kyrion Milo Arwen
Here, %1 ("wave") is the action we want to do to everyone. So what we do is save its value for later use, then SHIFT to get rid of it, and then start our normal looping process:
DO.CMD: if_1 goto Parm1Present echo Usage is: DO <what to do> <player> ... <player> exit Parm1Present: ; save %1 into the %s variable (%s == saved) save %1 ; then, SHIFT the command line to get to the first name Shift MainLoop: ; first, see if we have a %1 name to work on. ; If not, we're done so we just exit. if_1 goto doIt exit doIt: ; this will expand to "put wave Kodos", ; then "put wave Kyrion", etc. put %s %1 wait ; Now, shift the parms to get the next name on the line Shift goto MainLoop
