Open main menu

Difference between revisions of "AGIWiki/Logic syntax"

234 bytes added ,  15:17, 25 October 2018
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "<source lang=" to "<syntaxhighlight lang=")
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
Line 13: Line 13:


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 19: Line 19:
<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 40: Line 40:
lindirectv(v30,v32); *v30 = v32;
lindirectv(v30,v32); *v30 = v32;
rindirect(v30,v32);  v30 = *v32;
rindirect(v30,v32);  v30 = *v32;
</source>
</syntaxhighlight>


== If structures and test commands ==
== If structures and test commands ==
Line 50: Line 50:
   action commands
   action commands
}
}
</source>
</syntaxhighlight>


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


Carriage returns are not necessary:
Carriage returns are not necessary:
Line 67: Line 67:
<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>




Line 75: Line 75:
if (isset(f5) &&
if (isset(f5) &&
     greatern(v5,6)) { ......
     greatern(v5,6)) { ......
</source>
</syntaxhighlight>


Again, carriage returns are not necessary within the if statement:
Again, carriage returns are not necessary within the if statement:
Line 84: Line 84:
if (isset(f90) && equalv(v32,v34) &&
if (isset(f90) && equalv(v32,v34) &&
     greatern(v34,20)) { .......
     greatern(v34,20)) { .......
</source>
</syntaxhighlight>


A&nbsp;! placed in front of a command signifies a NOT.
A&nbsp;! placed in front of a command signifies a NOT.
Line 91: Line 91:
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 103: Line 103:


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 122: Line 122:
!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 130: Line 130:


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


which is equivalent to:
which is equivalent to:
Line 138: Line 138:


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


== Argument types ==
== Argument types ==
Line 196: Line 196:


if (obj.in.box(o2, 30, 60, 120, 40)) { .....
if (obj.in.box(o2, 30, 60, 120, 40)) { .....
</source>
</syntaxhighlight>


For a complete list of the commands and their argument types, see [[AGIWiki/Logic commands by name|Logic commands by name]].
For a complete list of the commands and their argument types, see [[AGIWiki/Logic commands by name|Logic commands by name]].
Line 211: Line 211:
if (has(i9)) { .....
if (has(i9)) { .....


</source>
</syntaxhighlight>
Messages can also be split over multiple lines:
Messages can also be split over multiple lines:


Line 217: Line 217:
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 inventory item names. This is important because some messages or inventory item names may contain parentheses 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 inventory item names. This is important because some messages or inventory item names may contain parentheses or commas, which could confuse the compiler. This is also the case for the said command which will be described shortly.
Line 224: Line 224:
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>


If quote marks are part of the message or inventory object, a \ should be placed in front of these. To use a \, \\ should be used. \n can also be used for a new line.
If quote marks are part of the message or inventory object, a \ should be placed in front of these. To use a \, \\ should be used. \n can also be used for a new line.
Line 232: Line 232:
<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 240: Line 240:


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 250: Line 250:
<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 label name can contain letters, numbers, and the characters '_' and '.'. No spaces are allowed.
Line 258: Line 258:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
goto(Label1);
goto(Label1);
</source>
</syntaxhighlight>


== Comments ==
== Comments ==
Line 270: Line 270:


/* Text between these are ignored */
/* Text between these are ignored */
</source>
</syntaxhighlight>


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


*/                  // uncomments
*/                  // uncomments
</source>
</syntaxhighlight>


'''Note:''' the fact that these comments can be nested is very different from almost every other language that uses these types of comments, including C, C , and Java.
'''Note:''' the fact that these comments can be nested is very different from almost every other language that uses these types of comments, including C, C , and Java.
Line 306: Line 306:
<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 312: Line 312:
<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 318: Line 318:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
print("You can't do that now.");
print("You can't do that now.");
</source>
</syntaxhighlight>


<nowiki>#message can be used anywhere in the file, so you do not have to set the message before you use it. </nowiki>
<nowiki>#message can be used anywhere in the file, so you do not have to set the message before you use it. </nowiki>
TrustedUser
2,147

edits