-
Notifications
You must be signed in to change notification settings - Fork 1
/
ch10.html
147 lines (137 loc) · 6.65 KB
/
ch10.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css">
td, th { border: 1px solid #c3c3c3; padding: 0 3px 0 3px; }
table { border-collapse: collapse; }
img { max-width: 100%; }
</style>
<meta name="generator" content="ReText 7.2.3">
<title>ch10</title>
<style type="text/css">
</style>
</head>
<body>
<p><a href="ch09.html">Previous</a> <a href="index.html">Index</a> <a href="ch11.html">Next</a></p>
<hr>
<h1>10 Axbasic</h1>
<h4>Table of Contents</h4>
<ul>
<li><a href="#10.1">10.1 Axbasic script example: Hello world!</a></li>
<li><a href="#10.2">10.2 Axbasic script example: Test script</a></li>
<li><a href="#10.3">10.3 Axbasic script example: Hunt The Wumpus!</a></li>
<li><a href="#10.4">10.4 Testing scripts</a></li>
<li><a href="#10.5">10.5 Running scripts as a task</a></li>
<li><a href="#10.6">10.6 Axbasic help</a></li>
<li><a href="#10.7">10.7 Retrieving Axmud data</a></li>
</ul>
<hr>
<p>Axbasic is Axmud's own scripting language, based on the BASIC language first released in the 1960s and which was commonly used on home computers in the 1970s and 80s.</p>
<p>BASIC is considered old-fashioned, but it has a distinct advantage in that most people already know how to use it and, even if not, it's simple enough to be learned in just a few hours.</p>
<p>The <a href="../tutorial/index.html">Axbasic Tutorial</a> is a complete guide to the features of Axbasic. This Section describes only the basics.</p>
<h2><a name="10.1">10.1 Axbasic script example: Hello world!</a></h2>
<p>Axmud's data directory (folder) can be found in your home directory. It contains a sub-directory called <strong>scripts</strong> which contains three example scripts.</p>
<p><strong>hello.bas</strong> is the traditional <em>Hello world!</em> script:</p>
<pre><code> REM A trivial Axbasic script
PRINT "Hellow world!"
END
</code></pre>
<p>If the temptation is too great, you can run the script to see what it does:</p>
<pre><code> ;runscript hello
;rs hello
</code></pre>
<p>The <strong>;runscript</strong> command assumes that there is a script called <strong>hello.bas</strong> in this directory. If it finds one, the script is executed. (This behaviour can be modified so that other directories are checked too, if desired.)</p>
<h2><a name="10.2">10.2 Axbasic script example: Test script</a></h2>
<p>The <strong>test.bas</strong> example script does nothing, at first. You can use it for testing Axbasic code.</p>
<p>Its main advantage is that it can be run with any of the following commands:</p>
<pre><code> ;runscript test
;rs test
;runscript
;rs
</code></pre>
<h2><a name="10.3">10.3 Axbasic script example: Hunt The Wumpus!</a></h2>
<p>The third example script, <strong>wumpus.bas</strong>, is a copy of the 1972 classic <em>Hunt the Wumpus</em>.</p>
<p>It’s not much fun to play, but nevertheless, Axbasic is compatible with BASIC programmes from this era and will run Hunt the Wumpus without complaints:</p>
<pre><code> ;runscript wumpus
;rs wumpus
</code></pre>
<h2><a name="10.4">10.4 Testing scripts</a></h2>
<p>Axbasic scripts can be tested without being run. Use the following command:</p>
<pre><code> ;checkscript wumpus
;cs wumpus
</code></pre>
<p>Hopefully, the test will report that there are no errors. (It would be surprising if you could find one, 45 years after the game was written!)</p>
<p>You can use the same command to check the <strong>test.bas</strong> script, simply by omitting the script name:</p>
<pre><code> ;checkscript
;cs
</code></pre>
<p>There is also a useful little command which opens a script in a text editor:</p>
<pre><code> ;editscript wumpus
;es wumpus
</code></pre>
<p>As always, if you leave out the script name, Axmud uses the 'test.bas' script:</p>
<pre><code> ;editscript
;es
</code></pre>
<h2><a name="10.5">10.5 Running scripts as a task</a></h2>
<p>You can use the <strong>;runscript</strong> command for simple scripts. It runs the script from beginning to end, without pausing.</p>
<p>This is fine for simple scripts, but often you'll want something more flexible. You will want the script to pause at certain times, or to wait for something to happen, or to display text in its own window. In these situations, you can use the Script task - one of Axmud's built-in tasks - to run the script on your behalf.</p>
<p>To run a script from inside the Script task, use the <strong>;runscriptask</strong> command:</p>
<pre><code> ;runscripttask wumpus
;rst wumpus
</code></pre>
<p>As always, if you don't specify a script name, the <strong>test.bas</strong> script is run:</p>
<pre><code> ;runscripttask
;rst
</code></pre>
<p>Some Axbasic keywords such as WAITARRIVE and WAITTRIG won't work unless the script is run from within a task. Here's an example of what scripts like these can do. (All lines beginning with an exclamation mark ( ! ) are comments, which are ignored.)</p>
<pre><code> ! Kill an orc and return home
! Move to the killing zone
MOVE "north"
MOVE "northwest"
MOVE "north"
SEND "open door"
MOVE "in"
! Wait for your character to arrive
WAITARRIVE
! Kill the orc
SEND "kill orc"
! Create a trigger to wait for the orc's death
WAITTRIG "You kill the orc"
! THe orc is now dead; go back home
SEND "open door"
MOVE "out"
MOVE "south"
MOVE "southeast"
MOVE "south"
! All Axbasic scripts must contain an END statement
END
</code></pre>
<h2><a name="10.6">10.6 Axbasic help</a></h2>
<p>Axmud provides extensive documentation on Axbasic's keywords and functions. A summary can be seen using this command:</p>
<pre><code> ;axbasichelp
;abh
</code></pre>
<p>The same command can be used to show help on a particular topic:</p>
<pre><code> ;axbasichelp send
;axbasichelp waittrig
</code></pre>
<h2><a name="10.7">10.7 Retrieving Axmud data</a></h2>
<p>Axbasic scripts enjoy full access to Axmud's internal data. Here's a brief example of how to exploit that capability.</p>
<pre><code> REM What am I?
PEEK guild$ = "guild.current.name"
IF guild$ = "thief" THEN
PRINT "I am a thief!"
ELSE
PRINT "I am not a thief!"
END IF
END
</code></pre>
<p>Most of Axmud's internal data can be accessed using strings like <strong>guild.current.name</strong>, and some of it can be modified using a POKE statement.</p>
<p>A complete list of strings that can be used in this way can be found in <a href="ch17.html">Section 17</a>.</p>
<p>(Note that, if you haven't set your current character's guild, then of course this script would not work as intended.)</p>
<hr>
<p><a href="ch09.html">Previous</a> <a href="index.html">Index</a> <a href="ch11.html">Next</a></p>
</body>
</html>