Open main menu

Difference between revisions of "AGI/Specifications/Logic"

m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "<source lang=" to "<syntaxhighlight lang=")
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
Line 21: Line 21:
     assign.v(v50,0);
     assign.v(v50,0);
     program.control();
     program.control();
</source>
</syntaxhighlight>


Multiple commands may be placed on the one line:
Multiple commands may be placed on the one line:
Line 27: Line 27:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
   reset(f6); reset(f7);
   reset(f6); reset(f7);
</source>
</syntaxhighlight>


Substitutions for the following action commands are available:
Substitutions for the following action commands are available:
Line 47: Line 47:
     lindirectv(v30,v32);  *v30 = v32;
     lindirectv(v30,v32);  *v30 = v32;
     rindirect(v30,v32);  v30 = *v32;
     rindirect(v30,v32);  v30 = *v32;
</source>
</syntaxhighlight>


===Conditionals and tests===
===Conditionals and tests===
Line 57: Line 57:
         <action commands>
         <action commands>
     }
     }
</source>
</syntaxhighlight>


or like this :
or like this :
Line 68: Line 68:
       <more action commands>
       <more action commands>
     }
     }
</source>
</syntaxhighlight>


Multiple commands can be placed in a single line:
Multiple commands can be placed in a single line:
Line 74: Line 74:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
     if (<test commands>) { <action Commands> } else { <more action commands> }
     if (<test commands>) { <action Commands> } else { <more action commands> }
</source>
</syntaxhighlight>


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.
Line 81: Line 81:
     if (isset(f5) &&
     if (isset(f5) &&
         greatern(v5,6)) { ......
         greatern(v5,6)) { ......
</source>
</syntaxhighlight>


  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:
Line 90: Line 90:
     if (isset(f90) && equalv(v32,v34)
     if (isset(f90) && equalv(v32,v34)
         && greatern(v34,20)) { .......
         && greatern(v34,20)) { .......
</source>
</syntaxhighlight>


A '''!''' placed in front of a command negates its result:
A '''!''' placed in front of a command negates its result:
Line 97: Line 97:
     if (!isset(f7)) {
     if (!isset(f7)) {
       ......
       ......
</source>
</syntaxhighlight>


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.
Line 109: Line 109:


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


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 128: Line 128:
     !lessn(v30,4)        v30 >= 4
     !lessn(v30,4)        v30 >= 4
     !lessv(v30,v32)      v30 >= v32
     !lessv(v30,v32)      v30 >= v32
</source>
</syntaxhighlight>


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:
Line 136: Line 136:


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


===Argument types===
===Argument types===
Line 163: Line 163:
     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)) { .....
</source>
</syntaxhighlight>


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 174: Line 174:
     if (has("Jetpack")) { .....
     if (has("Jetpack")) { .....
     if (has(io9)) { .....
     if (has(io9)) { .....
</source>
</syntaxhighlight>


Messages can also be split over multiple lines:
Messages can also be split over multiple lines:
Line 181: Line 181:
     print("This message is split "
     print("This message is split "
           "over multiple lines.");
           "over multiple lines.");
</source>
</syntaxhighlight>


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.
Line 188: Line 188:
     if (has("Buckazoid(s)")) { .....        // no ambiguity here about where
     if (has("Buckazoid(s)")) { .....        // no ambiguity here about where
                                             // the argument ends
                                             // the argument ends
</source>
</syntaxhighlight>


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.
Line 194: Line 194:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
     if (said(4,80)) { .....
     if (said(4,80)) { .....
</source>
</syntaxhighlight>


Words can also be given in place of the numbers:
Words can also be given in place of the numbers:
Line 201: Line 201:
     if (said("look")) { .....
     if (said("look")) { .....
     if (said("open","door")) { .....
     if (said("open","door")) { .....
</source>
</syntaxhighlight>


Quote marks must also be used around the words.
Quote marks must also be used around the words.
Line 211: Line 211:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
     Label1:
     Label1:
</source>
</syntaxhighlight>


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.
Line 217: Line 217:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
     goto(Label1);
     goto(Label1);
</source>
</syntaxhighlight>


===Comments===
===Comments===
Line 227: Line 227:
     [  Rest of line is ignored
     [  Rest of line is ignored
     /* Text between these are ignored */
     /* Text between these are ignored */
</source>
</syntaxhighlight>


The /*...*/ can be nested:
The /*...*/ can be nested:
Line 239: Line 239:
       print("Hey!");    // won't be run, still inside comments
       print("Hey!");    // won't be run, still inside comments
     */                  // uncomments
     */                  // uncomments
</source>
</syntaxhighlight>


===Defines===
===Defines===
Line 248: Line 248:
     #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."
</source>
</syntaxhighlight>


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:
Line 255: Line 255:
     draw(ego);
     draw(ego);
     print(room_descr);
     print(room_descr);
</source>
</syntaxhighlight>


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 269: Line 269:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
     #include "file.txt"
     #include "file.txt"
</source>
</syntaxhighlight>


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 280: Line 280:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
     #message 4 "You can't do that now."
     #message 4 "You can't do that now."
</source>
</syntaxhighlight>


Then you can give the message number as the parameter in commands:
Then you can give the message number as the parameter in commands:
Line 286: Line 286:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
     print(m4);
     print(m4);
</source>
</syntaxhighlight>


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:
Line 292: Line 292:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
     print("You can't do that now.");
     print("You can't do that now.");
</source>
</syntaxhighlight>


#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  


<syntaxhighlight 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))</syntaxhighlight>


, otherwise vd = 255.
, otherwise vd = 255.
Line 855: Line 855:
     ...
     ...
     show.pic();
     show.pic();
</source>
</syntaxhighlight>


:Any other order may crash the interpreter without any diagnostic messages.
:Any other order may crash the interpreter without any diagnostic messages.
Line 1,222: Line 1,222:
     set.string(s1,"test");
     set.string(s1,"test");
     unknown170(1);
     unknown170(1);
</source>
</syntaxhighlight>


:will automatically load the savegame named "test".
:will automatically load the savegame named "test".
Line 1,264: Line 1,264:
cycle.time(smoke, work);
cycle.time(smoke, work);
draw(smoke);
draw(smoke);
</source>
</syntaxhighlight>


From the game:
From the game:
Line 1,281: Line 1,281:
cycle.time(7, 152);
cycle.time(7, 152);
draw(7);
draw(7);
</source>
</syntaxhighlight>


Opening the door
Opening the door
Line 1,309: Line 1,309:
   }
   }
}
}
</source>
</syntaxhighlight>


From the game:
From the game:
Line 1,339: Line 1,339:
   }
   }
}
}
</source>
</syntaxhighlight>


===Unlocking the door===
===Unlocking the door===
Line 1,359: Line 1,359:
   }
   }
}
}
</source>
</syntaxhighlight>


From the game:
From the game:
Line 1,378: Line 1,378:
   }
   }
}
}
</source>
</syntaxhighlight>


===Knocking on the door===
===Knocking on the door===
Line 1,401: Line 1,401:
   }
   }
}
}
</source>
</syntaxhighlight>


From the game:
From the game:
Line 1,423: Line 1,423:
   }
   }
}
}
</source>
</syntaxhighlight>


===Fall rocks===
===Fall rocks===
Line 1,480: Line 1,480:
   }
   }
}
}
</source>
</syntaxhighlight>


From the game:
From the game:
Line 1,534: Line 1,534:
   }
   }
}
}
</source>
</syntaxhighlight>
TrustedUser
2,147

edits