Difference between revisions of "AGI/Specifications/Logic"

Jump to navigation Jump to search
m
Text replacement - "<source lang=" to "<syntaxhighlight lang="
(Fix syntax highlighting)
m (Text replacement - "<source lang=" to "<syntaxhighlight lang=")
Line 18: Line 18:
think they are using a flag).
think they are using a flag).


<source lang="cpp">
<syntaxhighlight lang="cpp">
     assign.v(v50,0);
     assign.v(v50,0);
     program.control();
     program.control();
Line 25: Line 25:
Multiple commands may be placed on the one line:
Multiple commands may be placed on the one line:


<source lang="cpp">
<syntaxhighlight lang="cpp">
   reset(f6); reset(f7);
   reset(f6); reset(f7);
</source>
</source>
Line 31: Line 31:
Substitutions for the following action commands are available:
Substitutions for the following action commands are available:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     increment(v30);      v30++;
     increment(v30);      v30++;
     decrement(v30);      v30--;
     decrement(v30);      v30--;
Line 53: Line 53:
An '''if''' structure looks like this:
An '''if''' structure looks like this:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if (<test commands>) {
     if (<test commands>) {
         <action commands>
         <action commands>
Line 61: Line 61:
or like this :
or like this :


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if (<test commands>) {
     if (<test commands>) {
         <action commands>
         <action commands>
Line 72: Line 72:
Multiple commands can be placed in a single line:
Multiple commands can be placed in a single line:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if (<test commands>) { <action Commands> } else { <more action commands> }
     if (<test commands>) { <action Commands> } else { <more action commands> }
</source>
</source>
Line 78: Line 78:
Test commands are coded like action commands except there is no semicolon. They are separated by && or || for AND or OR.
Test commands are coded like action commands except there is no semicolon. They are separated by && or || for AND or OR.


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if (isset(f5) &&
     if (isset(f5) &&
         greatern(v5,6)) { ......
         greatern(v5,6)) { ......
Line 85: Line 85:
  Multiple tests can be placed in a single line within the if statement:
  Multiple tests can be placed in a single line within the if statement:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if (lessn(v5,6) && (greatern(v5,2)) { .......
     if (lessn(v5,6) && (greatern(v5,2)) { .......


Line 94: Line 94:
A '''!''' placed in front of a command negates its result:
A '''!''' placed in front of a command negates its result:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if (!isset(f7)) {
     if (!isset(f7)) {
       ......
       ......
Line 101: Line 101:
Boolean expressions are not necessarily simplified so they must follow the rules set down by the file format. If test commands are to be ORred together, they must be placed in brackets.
Boolean expressions are not necessarily simplified so they must follow the rules set down by the file format. If test commands are to be ORred together, they must be placed in brackets.


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if ((isset(f1) || isset(f2)) {
     if ((isset(f1) || isset(f2)) {
       ......
       ......
Line 115: Line 115:
The following test commands and operations are equivalent:
The following test commands and operations are equivalent:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     equaln(v30,4)        v30 == 4
     equaln(v30,4)        v30 == 4
     equalv(v30,v32)      v30 == v32
     equalv(v30,v32)      v30 == v32
Line 132: Line 132:
Also, flags can be tested for by just using the name of the flag:
Also, flags can be tested for by just using the name of the flag:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if (f6) { .....
     if (f6) { .....


Line 160: Line 160:
Compilers can enforce type checking, so that the programmer must use the correct prefix for an argument so that they know they are using the right type. Decoders should display arguments with the right type.
Compilers can enforce type checking, so that the programmer must use the correct prefix for an argument so that they know they are using the right type. Decoders should display arguments with the right type.


<source lang="cpp">
<syntaxhighlight lang="cpp">
     move.obj(so4,80,120,2,f66);
     move.obj(so4,80,120,2,f66);
     if (obj.in.box(so2,30,60,120,40)) { .....
     if (obj.in.box(so2,30,60,120,40)) { .....
Line 169: Line 169:
Messages and inventory items may be given in either numerical text format:
Messages and inventory items may be given in either numerical text format:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     print("He's not here.");
     print("He's not here.");
     print(m12);
     print(m12);
Line 178: Line 178:
Messages can also be split over multiple lines:
Messages can also be split over multiple lines:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     print("This message is split "
     print("This message is split "
           "over multiple lines.");
           "over multiple lines.");
Line 185: Line 185:
Quote marks must be used around messages and object names. This is important because some messages or object names may contain brackets or commas, which could confuse the compiler. This is also the case for the '''said''' command which will be described shortly.
Quote marks must be used around messages and object names. This is important because some messages or object names may contain brackets or commas, which could confuse the compiler. This is also the case for the '''said''' command which will be described shortly.


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if (has("Buckazoid(s)")) { .....        // no ambiguity here about where
     if (has("Buckazoid(s)")) { .....        // no ambiguity here about where
                                             // the argument ends
                                             // the argument ends
Line 192: Line 192:
The '''said''' test command uses different parameters to all the other commands. Where as the others use 8 bit arguments (0--255), '''said''' takes 16 bit arguments (0--65535). Also, the number of arguments in a '''said''' command can vary. The numbers given in the arguments are the word group numbers from the '''words.tok''' file.
The '''said''' test command uses different parameters to all the other commands. Where as the others use 8 bit arguments (0--255), '''said''' takes 16 bit arguments (0--65535). Also, the number of arguments in a '''said''' command can vary. The numbers given in the arguments are the word group numbers from the '''words.tok''' file.


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if (said(4,80)) { .....
     if (said(4,80)) { .....
</source>
</source>
Line 198: Line 198:
Words can also be given in place of the numbers:
Words can also be given in place of the numbers:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     if (said("look")) { .....
     if (said("look")) { .....
     if (said("open","door")) { .....
     if (said("open","door")) { .....
Line 209: Line 209:
Labels are given like this:
Labels are given like this:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     Label1:
     Label1:
</source>
</source>
Line 215: Line 215:
The label name can contain letters, numbers, and the characters "_" and ".". No spaces are allowed. The '''goto''' command takes one parameter, the name of a label.
The label name can contain letters, numbers, and the characters "_" and ".". No spaces are allowed. The '''goto''' command takes one parameter, the name of a label.


<source lang="cpp">
<syntaxhighlight lang="cpp">
     goto(Label1);
     goto(Label1);
</source>
</source>
Line 223: Line 223:
There are three ways that comments can be used.
There are three ways that comments can be used.


<source lang="cpp">
<syntaxhighlight lang="cpp">
     // Rest of line is ignored
     // Rest of line is ignored
     [  Rest of line is ignored
     [  Rest of line is ignored
Line 231: Line 231:
The /*...*/ can be nested:
The /*...*/ can be nested:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     /* comment start
     /* comment start
       print("Hello");    // won't be run
       print("Hello");    // won't be run
Line 245: Line 245:
To give vars, flags etc. proper names the #define command is used. The name of the define is given followed by the define value:
To give vars, flags etc. proper names the #define command is used. The name of the define is given followed by the define value:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     #define ego o0
     #define ego o0
     #define room_descr "This is a large hall with tall pillars down each side."
     #define room_descr "This is a large hall with tall pillars down each side."
Line 252: Line 252:
Then the define name can be used in place of the define value:
Then the define name can be used in place of the define value:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     draw(ego);
     draw(ego);
     print(room_descr);
     print(room_descr);
Line 267: Line 267:
You can include another file in your logic source code by using the #include command:
You can include another file in your logic source code by using the #include command:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     #include "file.txt"
     #include "file.txt"
</source>
</source>
Line 278: Line 278:
In some cases you may want to assign a specific number to a message so you can refer to it in other places. This is done by using the #message command, followed by the number of the message then the message itself:
In some cases you may want to assign a specific number to a message so you can refer to it in other places. This is done by using the #message command, followed by the number of the message then the message itself:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     #message 4 "You can't do that now."
     #message 4 "You can't do that now."
</source>
</source>
Line 284: Line 284:
Then you can give the message number as the parameter in commands:
Then you can give the message number as the parameter in commands:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     print(m4);
     print(m4);
</source>
</source>
Line 290: Line 290:
Or embed the message in commands as normal and the number you assigned to it before will be used:
Or embed the message in commands as normal and the number you assigned to it before will be used:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     print("You can't do that now.");
     print("You can't do that now.");
</source>
</source>
Line 783: Line 783:
:If both objects n and m are on the screen, then  
:If both objects n and m are on the screen, then  


<source lang="cpp">vd = abs(x(n) - x(m)) + abs(y(n) - y(m))</source>
<syntaxhighlight lang="cpp">vd = abs(x(n) - x(m)) + abs(y(n) - y(m))</source>


, otherwise vd = 255.
, otherwise vd = 255.
Line 849: Line 849:
:ATTENTION! Please use the following sequence of commands when loading PICTURE resources in the interpreter memory:
:ATTENTION! Please use the following sequence of commands when loading PICTURE resources in the interpreter memory:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     load.pic(n);
     load.pic(n);
     draw.pic(n);
     draw.pic(n);
Line 1,219: Line 1,219:
:Example:
:Example:


<source lang="cpp">
<syntaxhighlight lang="cpp">
     set.string(s1,"test");
     set.string(s1,"test");
     unknown170(1);
     unknown170(1);
Line 1,253: Line 1,253:
From the book:
From the book:


<source lang="cpp">
<syntaxhighlight lang="cpp">
animate.obj(smoke);
animate.obj(smoke);
ignore.horizon(smoke);
ignore.horizon(smoke);
Line 1,268: Line 1,268:
From the game:
From the game:


<source lang="cpp">
<syntaxhighlight lang="cpp">
animate.obj(7);
animate.obj(7);
ignore.horizon(7);
ignore.horizon(7);
Line 1,287: Line 1,287:
From the book:
From the book:


<source lang="cpp">
<syntaxhighlight lang="cpp">
if (said( open, door)) {    // must be close enough
if (said( open, door)) {    // must be close enough
   if (posn( ego, 86, 120, 106, 133)) {
   if (posn( ego, 86, 120, 106, 133)) {
Line 1,313: Line 1,313:
From the game:
From the game:


<source lang="cpp">
<syntaxhighlight lang="cpp">
if (said(OPEN, DOOR||DOORS||DOORWAY||DOORWAYS)) {
if (said(OPEN, DOOR||DOORS||DOORWAY||DOORWAYS)) {
   if (posn(0, 86, 120, 106, 133)) {
   if (posn(0, 86, 120, 106, 133)) {
Line 1,345: Line 1,345:
From the book:
From the book:


<source lang="cpp">
<syntaxhighlight lang="cpp">
if (said( unlock, door)) {    // must be close enough
if (said( unlock, door)) {    // must be close enough
   if (posn( ego, 86, 120, 106, 133)) {
   if (posn( ego, 86, 120, 106, 133)) {
Line 1,363: Line 1,363:
From the game:
From the game:


<source lang="cpp">
<syntaxhighlight lang="cpp">
if (said(UNLATCH||UNLOCK, DOOR||DOORS||DOORWAY||DOORWAYS)) {
if (said(UNLATCH||UNLOCK, DOOR||DOORS||DOORWAY||DOORWAYS)) {
   if (posn(0, 86, 120, 106, 133)) {
   if (posn(0, 86, 120, 106, 133)) {
Line 1,384: Line 1,384:
From the book:
From the book:


<source lang="cpp">
<syntaxhighlight lang="cpp">
if ((said( knock, at, door) || said( knock) ||
if ((said( knock, at, door) || said( knock) ||
     said( knock, on, door) || said( knock, door)) {
     said( knock, on, door) || said( knock, door)) {
Line 1,405: Line 1,405:
From the game:
From the game:


<source lang="cpp">
<syntaxhighlight lang="cpp">
if (said(BANG||KNOCK||RAP||TAP) ||
if (said(BANG||KNOCK||RAP||TAP) ||
     said(BANG||KNOCK||RAP||TAP, DOOR||DOORS||DOORWAY||DOORWAYS)) {
     said(BANG||KNOCK||RAP||TAP, DOOR||DOORS||DOORWAY||DOORWAYS)) {
Line 1,433: Line 1,433:
From the book:
From the book:


<source lang="cpp">
<syntaxhighlight lang="cpp">
if (hit.special) {
if (hit.special) {
   if ((rf2 || rf3 || rf4)) {
   if ((rf2 || rf3 || rf4)) {
Line 1,484: Line 1,484:
From the game:
From the game:


<source lang="cpp">
<syntaxhighlight lang="cpp">
if (isset(3)) {    [ hit.special
if (isset(3)) {    [ hit.special
   if (isset(222) || isset(223) || isset(224)) {    // rf2, rf3, rf4
   if (isset(222) || isset(223) || isset(224)) {    // rf2, rf3, rf4
TrustedUser
2,147

edits

Navigation menu