Open main menu

Difference between revisions of "AGI/Specifications/Logic"

Fix syntax highlighting
m (behaviour -> behavior)
(Fix syntax highlighting)
Line 18: Line 18:
think they are using a flag).
think they are using a flag).


<syntax type="C++">
<source lang="cpp">
     assign.v(v50,0);
     assign.v(v50,0);
     program.control();
     program.control();
</syntax>
</source>


Multiple commands may be placed on the one line:
Multiple commands may be placed on the one line:


<syntax type="C++">
<source lang="cpp">
   reset(f6); reset(f7);
   reset(f6); reset(f7);
</syntax>
</source>


Substitutions for the following action commands are available:
Substitutions for the following action commands are available:


<syntax type="C++">
<source lang="cpp">
     increment(v30);      v30++;
     increment(v30);      v30++;
     decrement(v30);      v30--;
     decrement(v30);      v30--;
Line 47: Line 47:
     lindirectv(v30,v32);  *v30 = v32;
     lindirectv(v30,v32);  *v30 = v32;
     rindirect(v30,v32);  v30 = *v32;
     rindirect(v30,v32);  v30 = *v32;
</syntax>
</source>


===Conditionals and tests===
===Conditionals and tests===
Line 53: Line 53:
An '''if''' structure looks like this:
An '''if''' structure looks like this:


<syntax type="C++">
<source lang="cpp">
     if (<test commands>) {
     if (<test commands>) {
         <action commands>
         <action commands>
     }
     }
</syntax>
</source>


or like this :
or like this :


<syntax type="C++">
<source lang="cpp">
     if (<test commands>) {
     if (<test commands>) {
         <action commands>
         <action commands>
Line 68: Line 68:
       <more action commands>
       <more action commands>
     }
     }
</syntax>
</source>


Multiple commands can be placed in a single line:
Multiple commands can be placed in a single line:


<syntax type="C++">
<source lang="cpp">
     if (<test commands>) { <action Commands> } else { <more action commands> }
     if (<test commands>) { <action Commands> } else { <more action commands> }
</syntax>
</source>


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.


<syntax type="C++">
<source lang="cpp">
     if (isset(f5) &&
     if (isset(f5) &&
         greatern(v5,6)) { ......
         greatern(v5,6)) { ......
</syntax>
</source>


  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:


<syntax type="C++">
<source lang="cpp">
     if (lessn(v5,6) && (greatern(v5,2)) { .......
     if (lessn(v5,6) && (greatern(v5,2)) { .......


     if (isset(f90) && equalv(v32,v34)
     if (isset(f90) && equalv(v32,v34)
         && greatern(v34,20)) { .......
         && greatern(v34,20)) { .......
</syntax>
</source>


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


<syntax type="C++">
<source lang="cpp">
     if (!isset(f7)) {
     if (!isset(f7)) {
       ......
       ......
</syntax>
</source>


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.


<syntax type="C++">
<source lang="cpp">
     if ((isset(f1) || isset(f2)) {
     if ((isset(f1) || isset(f2)) {
       ......
       ......
Line 109: Line 109:


     if (isset(1) || (isset(2) && isset(3))) {    // is NOT legal
     if (isset(1) || (isset(2) && isset(3))) {    // is NOT legal
</syntax>
</source>


Depending on the compiler, simplification of boolean expressions may be supported, so the above may not apply in all cases (although if these are rules are followed then the logic will work with all compilers).
Depending on the compiler, simplification of boolean expressions may be supported, so the above may not apply in all cases (although if these are rules are followed then the logic will work with all compilers).
Line 115: Line 115:
The following test commands and operations are equivalent:
The following test commands and operations are equivalent:


<syntax type="C++">
<source lang="cpp">
     equaln(v30,4)        v30 == 4
     equaln(v30,4)        v30 == 4
     equalv(v30,v32)      v30 == v32
     equalv(v30,v32)      v30 == v32
Line 128: Line 128:
     !lessn(v30,4)        v30 >= 4
     !lessn(v30,4)        v30 >= 4
     !lessv(v30,v32)      v30 >= v32
     !lessv(v30,v32)      v30 >= v32
</syntax>
</source>


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:


<syntax type="C++">
<source lang="cpp">
     if (f6) { .....
     if (f6) { .....


     if (v7 > 0 && !f6) { .....
     if (v7 > 0 && !f6) { .....
</syntax>
</source>


===Argument types===
===Argument types===
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.


<syntax type="C++">
<source 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)) { .....
</syntax>
</source>


A complete list of the commands and their argument types is available in [[AGI/Specifications/Resources#Command_list_and_argument_typesas | Command list and argument types table]].
A complete list of the commands and their argument types is available in [[AGI/Specifications/Resources#Command_list_and_argument_typesas | Command list and argument types table]].
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:


<syntax type="C++">
<source lang="cpp">
     print("He's not here.");
     print("He's not here.");
     print(m12);
     print(m12);
     if (has("Jetpack")) { .....
     if (has("Jetpack")) { .....
     if (has(io9)) { .....
     if (has(io9)) { .....
</syntax>
</source>


Messages can also be split over multiple lines:
Messages can also be split over multiple lines:


<syntax type="C++">
<source lang="cpp">
     print("This message is split "
     print("This message is split "
           "over multiple lines.");
           "over multiple lines.");
</syntax>
</source>


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.


<syntax type="C++">
<source 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
</syntax>
</source>


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.


<syntax type="C++">
<source lang="cpp">
     if (said(4,80)) { .....
     if (said(4,80)) { .....
</syntax>
</source>


Words can also be given in place of the numbers:
Words can also be given in place of the numbers:


<syntax type="C++">
<source lang="cpp">
     if (said("look")) { .....
     if (said("look")) { .....
     if (said("open","door")) { .....
     if (said("open","door")) { .....
</syntax>
</source>


Quote marks must also be used around the words.
Quote marks must also be used around the words.
Line 209: Line 209:
Labels are given like this:
Labels are given like this:


<syntax type="C++">
<source lang="cpp">
     Label1:
     Label1:
</syntax>
</source>


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.


<syntax type="C++">
<source lang="cpp">
     goto(Label1);
     goto(Label1);
</syntax>
</source>


===Comments===
===Comments===
Line 223: Line 223:
There are three ways that comments can be used.
There are three ways that comments can be used.


<syntax type="C++">
<source lang="cpp">
     // Rest of line is ignored
     // Rest of line is ignored
     [  Rest of line is ignored
     [  Rest of line is ignored
     /* Text between these are ignored */
     /* Text between these are ignored */
</syntax>
</source>


The /*...*/ can be nested:
The /*...*/ can be nested:


<syntax type="C++">
<source lang="cpp">
     /* comment start
     /* comment start
       print("Hello");    // won't be run
       print("Hello");    // won't be run
Line 239: Line 239:
       print("Hey!");    // won't be run, still inside comments
       print("Hey!");    // won't be run, still inside comments
     */                  // uncomments
     */                  // uncomments
</syntax>
</source>


===Defines===
===Defines===
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:


<syntax type="C++">
<source 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."
</syntax>
</source>


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:


<syntax type="C++">
<source lang="cpp">
     draw(ego);
     draw(ego);
     print(room_descr);
     print(room_descr);
</syntax>
</source>


Define names can only be used in arguments of commands (including gotos and the v0 == 3 type syntax), although some compilers may allow you to use them anywhere.
Define names can only be used in arguments of commands (including gotos and the v0 == 3 type syntax), although some compilers may allow you to use them anywhere.
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:


<syntax type="C++">
<source lang="cpp">
     #include "file.txt"
     #include "file.txt"
</syntax>
</source>


When the compiler encounters the above line, it will replace it with the contents of file.txt.
When the compiler encounters the above line, it will replace it with the contents of file.txt.
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:


<syntax type="C++">
<source lang="cpp">
     #message 4 "You can't do that now."
     #message 4 "You can't do that now."
</syntax>
</source>


Then you can give the message number as the parameter in commands:
Then you can give the message number as the parameter in commands:


<syntax type="C++">
<source lang="cpp">
     print(m4);
     print(m4);
</syntax>
</source>


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:


<syntax type="C++">
<source lang="cpp">
     print("You can't do that now.");
     print("You can't do that now.");
</syntax>
</source>


#message can be used anywhere in the file, so you do not have to set the message before you use it.
#message can be used anywhere in the file, so you do not have to set the message before you use it.
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  


<syntax type="C++">vd = abs(x(n) - x(m)) + abs(y(n) - y(m))</syntax>
<source 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:


<syntax type="C++">
<source lang="cpp">
     load.pic(n);
     load.pic(n);
     draw.pic(n);
     draw.pic(n);
Line 855: Line 855:
     ...
     ...
     show.pic();
     show.pic();
</syntax>
</source>


:Any other order may crash the interpreter without any diagnostic messages.
:Any other order may crash the interpreter without any diagnostic messages.
Line 1,253: Line 1,253:
From the book:
From the book:


<syntax type="C++">
<source lang="cpp">
animate.obj(smoke);
animate.obj(smoke);
ignore.horizon(smoke);
ignore.horizon(smoke);
Line 1,264: Line 1,264:
cycle.time(smoke, work);
cycle.time(smoke, work);
draw(smoke);
draw(smoke);
</syntax>
</source>


From the game:
From the game:


<syntax type="C++">
<source lang="cpp">
animate.obj(7);
animate.obj(7);
ignore.horizon(7);
ignore.horizon(7);
Line 1,281: Line 1,281:
cycle.time(7, 152);
cycle.time(7, 152);
draw(7);
draw(7);
</syntax>
</source>


Opening the door
Opening the door
Line 1,287: Line 1,287:
From the book:
From the book:


<syntax type="C++">
<source 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,309: Line 1,309:
   }
   }
}
}
</syntax>
</source>


From the game:
From the game:


<syntax type="C++">
<source 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,339: Line 1,339:
   }
   }
}
}
</syntax>
</source>


===Unlocking the door===
===Unlocking the door===
Line 1,345: Line 1,345:
From the book:
From the book:


<syntax type="C++">
<source 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,359: Line 1,359:
   }
   }
}
}
</syntax>
</source>


From the game:
From the game:


<syntax type="C++">
<source 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,378: Line 1,378:
   }
   }
}
}
</syntax>
</source>


===Knocking on the door===
===Knocking on the door===
Line 1,384: Line 1,384:
From the book:
From the book:


<syntax type="C++">
<source 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,401: Line 1,401:
   }
   }
}
}
</syntax>
</source>


From the game:
From the game:


<syntax type="C++">
<source 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,423: Line 1,423:
   }
   }
}
}
</syntax>
</source>


===Fall rocks===
===Fall rocks===
Line 1,433: Line 1,433:
From the book:
From the book:


<syntax type="C++">
<source lang="cpp">
if (hit.special) {
if (hit.special) {
   if ((rf2 || rf3 || rf4)) {
   if ((rf2 || rf3 || rf4)) {
Line 1,480: Line 1,480:
   }
   }
}
}
</syntax>
</source>


From the game:
From the game:


<syntax type="C++">
<source 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
Line 1,534: Line 1,534:
   }
   }
}
}
</syntax>
</source>
TrustedUser
2,147

edits