Selecting an Editor
Notepad is what most people use for script making/editing. This is fine, and Notepad is a good Editor to use until the size of the script gets bigger than what Notepad can handle, and then your stuck. I use Notepad myself when I'm just making a simple edit to a script, it's both quick and easy.
I don't personally like using Wordpad as an Editor, mainly for the fact that if you don't save the file right, the program will add font information and a lot of useless stuff that just messes up the entire script.
I recommend Ultraedit for both editing and making scripts from start. It can handle large files, saves the files as they should be, and has a lot of more advanced features, including a better find/replace, highlighting and macros.
Now we have decided upon which Editor to use, we'll move right along to...
Label Names
This sounds simple, but I've noticed a lot of people don't follow it too well. You should, when writing a script, try to give your labels names that actually fit them. If not you may find that when others look at it, or when you come back to look at it in 6 months, that you haven't got a clue what it does.
An example of good label naming is this:
CheckRoom:
put look
match AtThePark [Town Square, Small Park]
match AtTSC [Town Square Central]
matchwait
Let's explain why this is good. First off, the entire sub is named CheckRoom. Wonder what it does? Not too hard to guess. Now, the 2 matches possible are named AtThePark and AtTSC. These are both logical, and obvious statements.
It's not too hard to name labels good, it's simply an act of laziness not to.
Spacing/Presentation
Being able to read through the scripts you have written is also an important factor. If your script looks like a spider has run all over Notepad, then it's gonna take you longer to edit it.
Leaving a blank line between subs is something that I find helps a lot. Not only does it help you distinguish between the start/end of each sub, but it also looks neater.
Example:
CheckRoom:
put look
match AtThePark [Town Square, Small Park]
match AtTSC [Town Square Central]
matchwait
CheckRoom2:
put look
match AtTSE [Town Square East]
match AtTSW [Town Square West]
matchwait
This reads a lot better than:
CheckRoom:
put look
match AtThePark [Town Square, Small Park]
match AtTSC [Town Square Central]
matchwait
CheckRoom2:
put look
match AtTSE [Town Square East]
match AtTSW [Town Square West]
matchwait
Error Checking/Preventing
If your script is going to be only for personal use, and assuming you know it's limitations, then error checking fully is not so needed. However if you aim to let others use the script, then removing all things that could cause errors is vital.
One of the most common errors, is the 'GOTO label not found!' error. This can be caused by many things, including:
1. You've used the counter variable and a 'goto %c' type function, and the number has exceeded the parameters you were expecting.
2. Incorrect spelling of the name of a label. 'goto strt' instead of 'goto start' for example.
These type of errors can be found/fixed with the aid of a label named LabelError.
The LabelError sub is used as a 'fallout' sub. Before the FE gives you the 'GOTO label not found!' error is look for a sub named LabelError:. Knowing this, you can in fact catch the error in the script and prevent it. Something like this:
CounterSet:
counter set 1
Start:
counter add 1
goto %c
1:
echo 1
goto Start
2:
echo 2
goto Start
3:
echo 3
goto Start
LabelError:
goto CounterSet
Another common problem that causes errors is because the script hasn't been run properly, whether run from the wrong room or whatever, if you can get the script to recognise this, and warn the user of it, you've eliminated yet another problem.
An Example would be to change:
CheckRoom:
put look
match AtThePark [Town Square, Small Park]
match AtTSC [Town Square Central]
matchwait
To:
CheckRoom:
put look
match AtThePark [Town Square, Small Park]
match AtTSC [Town Square Central]
match Lost Obvious
matchwait
This is another 'fallout' style method of writing Scripts. If you are not at the park or TSC, then the 'Obvious' will match up, thus alerting the script that the user is not in either of the required rooms.
If your scripts use command line variables (%0-%9) then make sure you put in a check to make sure they have been entered.
This is done by using if_0 to if_9
Example:
Start:
put skin %1
put search %1
Would become:
if_1 goto Start
echo *** The correct usage of this script is .scriptname critter ***
exit
Start:
put skin %1
put search %1
That removes errors where variables are not inputted.
Misc. Tips
1. Try to substitute container name, weapon names etc for %container and %weapon. Thus making the script Universal.
2. Try to test the Script on more than one character. Him/her or he/she will mess you up at least once in your scripting life.
3. For debugging, add echos just after the label names to help you pinpoint where errors are. Such as:
RoomCheck:
echo Now in RoomCheck
This will save you looking through all the code to find the specific section where the error is.
-=Insomniac=- reg