Games-Axmud
view release on metacpan or search on metacpan
share/docs/tutorial/ch19.mkd view on Meta::CPAN
PRINT "...world!"
END
##<a name="19.4">19.4 OPTION REQUIRE</a>
From time to time, Axbasic undergoes small changes and improvements. If you're making use of some exciting new feature, you can tell Axbasic not to run the script on an older version of Axmud.
The current version of Axbasic, at the time of writing, is 1.002:
! Don't run on older versions of Axmud
OPTION REQUIRE 1.002
The earliest version of Axbasic was 1.0, so using this line is the same as omitting OPTION REQUIRE altogether:
! Run on all versions of Axmud
OPTION REQUIRE 1.0
By the way, the **Version ()** function returns the current Axbasic version.
PRINT Version ()
##<a name="19.5">19.5 OPTION TYPO</a>
It's just too easy to mis-type a variable like **string$**, in which case your script won't work as intended. Mistakes of this kind are notoriously difficult to diagnose.
The solution is to use OPTION TYPO, which tells Axbasic that all variables will be *declared* (in a GLOBAL or LOCAL statement) before they are used.
OPTION TYPO
GLOBAL name$, address$, phone_number
Now, if you type the following line (in which **address$** has been misspelled), you'll get an error with a line number. Because you know exactly where the problem is, it won't take long to spot the typo.
PRINT adress$
OPTION TYPO is strongly recommended for all of your Axbasic scripts.
##<a name="19.6">19.6 OPTION PSEUDO</a>
Client commands are normally typed in Axmud's main window, but any part of the code can execute a client command. (Internally, this is known as a *pseudo command*.)
In Axbasic, we use a CLIENT statement.
CLIENT "starttask compass"
Nearly every client command displays a confirmation (success) message in the main window. If there's a problem, an error message is displayed there instead. We can change what happens as a result of the CLIENT statement in any of the following ways.
OPTION PSEUDO "show_all"
This shows all system messages generated by the client command, as if the user had typed it themselves.
OPTION PSEUDO "hide_complete"
This shows any error messages in the main window, but not the confirmation message. (This is the default behaviour if no OPTION PSEUDO statement is used.)
OPTION PSEUDO "hide_system"
This hides any error messages, as well as any confirmation message.
OPTION PSEUDO "win_error"
This displays a confirmation message in the main window, but any error messages appear in a dialogue (popup) window.
OPTION PSEUDO "win_only"
This displays both confirmation and error messages in a dialogue (popup) window.
##<a name="19.7">19.7 OPTION REDIRECT</a>
OPTION REDIRECT
Axbasic scripts can create their own task window. A WRITEWIN statement display text in that task window. However, if the task window isn't open, nothing is displayed.
OPTION REDIRECT redirects text into the main window, if the task window has been closed for some reason.
##<a name="19.8">19.8 OPTION PERSIST</a>
OPTION PERSIST
Interfaces can be created with an ADDTRIG, ADDALIAS, ADDMACRO, ADDTIMER or ADDHOOK statement. Normally, those interfaces are destroyed as soon as the script stops running, but OPTION PERSIST prevents that destruction.
##<a name="19.9">19.9 OPTION ANGLE</a>
OPTION ANGLE DEGREES
Axbasic's trignometric functions like **Sin ()** and **Cos ()** expect angles measured in radians. If you'd prefer them to expect angles measured in degrees, you can use OPTION ANGLE DEGREES.
OPTION ANGLE RADIANS
This statement is useful for clarifying to any humans reading your code that you'll be using radians, not degrees.
##<a name="19.10">19.10 Advanced client commands</a>
An Axbasic script can be run using a client command. **;runscript** runs the **test.bas** script, and **;runscript wumpus** runs the **wumpus.bas** script.
When you try to run a script, Axbasic looks for a file in the default directory (folder), as we described in [Section 2](ch02.html).
You can find the location of this directory using the **;listdirectory** command. On a Linux system, the output will look something like this:
List of Axbasic directories
0 /home/myname/axmud-data/data/scripts
Client ';listdirectory' : Directory list displayed (found 1 directory)
You can add more directories to that list, if you want to. If the right file isn't found in the first directory, Axbasic will look in the second, then in the third (and so on).
To add a directory to the list, use the **;adddirectory** command.
;addirectory
If you already know the full directory path, you can specify it. (We enclose the path inside diamond brackets, just in case it contains space characters.)
;addirectory <home/myname/mydir>
The **;listdirectory** command gives each directory a number; you'll need that number if you want to remove a directory from the list.
;deletedirectory 2
An alternative approach is to specify the full file path every time you run the script.
;runscript -p <home/myname/mydir/myscript.bas>
When you run a script as a task, the **;runscripttask** command provides a number of options, two of which might be useful to you.
Firstly, an Axbasic script runs from beginning to end. A script that runs on a continuous loop would run indefinitely, meaning that Axmud itself would appear to freeze.
In previous Sections you learned to use PAUSE statements. When the script pauses, control is returned to Axmud for a short time. In this way, both Axmud and Axbasic can run code (almost) simultaneously.
( run in 1.034 second using v1.01-cache-2.11-cpan-364913b4093 )