Open main menu

Difference between revisions of "AGI/Specifications/Logic"

Wikify and fill in differences from SGML. Work in Progress
(→‎Knocking on the door: -- adding image)
(Wikify and fill in differences from SGML. Work in Progress)
Line 1: Line 1:
=The LOGIC language=
=The script language=


<span id="Logic"></span>
<span id="Logic"></span>
==LOGIC syntax==
==Source code conventions==


This is the ''official'' LOGIC syntax that has been decided on. It is not the same syntax as Sierra used. All LOGIC decoders and compilers should comply with this syntax, so that programmers can be sure that code they produce can be used properly with any program.
This section lists conventions that will be adopted in the AGI script
language description in this document. They may differ from Sierra's
original syntax, but the resulting bytecode is strictly the same.


===Action Commands===
===Commands and operators===


Normal action commands are specified by the command name followed by brackets which contain the arguments, separated by commas. A semicolon is placed after the brackets. The brackets are required even if there are no arguments. The arguments given must have the correct prefix for that type of argument as explained later in this document (this is to make sure the programmer does not use a var, for example, when they think they are using a flag).
Normal commands are specified by the command name followed by
brackets which contain the arguments, separated by commas. A semicolon
is placed after the brackets. The brackets are required even if there
are no arguments. The arguments given must have the correct prefix for
that type of argument as explained later in this document (this is to
make sure the programmer does not use a var, for example, when they
think they are using a flag).


<syntax type="C++">
<syntax type="C++">
Line 41: Line 49:
</syntax>
</syntax>


===if structures and test commands===
===Conditionals and tests===


An if structure looks like this:
An '''if''' structure looks like this:


<syntax type="C++">
<syntax type="C++">
Line 62: Line 70:
</syntax>
</syntax>


Carriage returns are not necessary:
Multiple commands can be placed in a single line:


<syntax type="C++">
<syntax type="C++">
Line 75: Line 83:
</syntax>
</syntax>


Again, carriage returns are not necessary within the if statement:
Multiple tests can be placed in a single line within the if statement:


<syntax type="C++">
<syntax type="C++">
Line 84: Line 92:
</syntax>
</syntax>


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


<syntax type="C++">
<syntax type="C++">
Line 105: Line 113:
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).


Substitutions for the following test commands are available:
The following test commands and operations are equivalent:


<syntax type="C++">
<syntax type="C++">
Line 146: Line 154:
The said test command uses its own special arguments which will be described later.
The said test command uses its own special arguments which will be described later.


Each of these types of arguments is given by the prefix and then a number from 0--255, e.g. v5, f6, m27, o2.
Each of these types of arguments is given by the prefix and then a number from 0--255, e.g. '''v5''', '''f6''', '''m27''', '''o2'''.


The word type is words that the player has typed in, not words that are stored in the words.tok file. Strings are the temporary string variables stored in memory, not to be confused with messages (that are stored in the LOGIC resources). Controllers are menu items and keys.
The "word" type is words that the player has typed in, not words that are stored in the '''words.tok''' file. Strings are the temporary string variables stored in memory, not to be confused with messages (that are stored in the LOGIC resources). Controllers are menu items and keys.


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.
Line 157: Line 165:
</syntax>
</syntax>


A complete list of the commands and their argument types is available as part of AGI Specs.
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]].


Messages and inventory items may be given in either numerical text format:
Messages and inventory items may be given in either numerical text format:
Line 175: Line 183:
</syntax>
</syntax>


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++">
<syntax type="C++">
Line 182: Line 190:
</syntax>
</syntax>


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++">
<syntax type="C++">
Line 197: Line 205:
Quote marks must also be used around the words.
Quote marks must also be used around the words.


===Labels and the goto command===
===Labels and the '''goto''' command===


Labels are given like this:
Labels are given like this:
Line 205: Line 213:
</syntax>
</syntax>


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. The '''goto''' command takes one parameter, the name of a label.
 
The goto command takes one parameter, the name of a label.


<syntax type="C++">
<syntax type="C++">
Line 292: Line 298:
===The return command===
===The return command===


The return command is just a normal action command (number 0), with no arguments. This must be the last command in every logic.
The return command is just a normal action command (number 0), with no arguments. This must be the last command in every script.


<span id="CommandRef"></span>
<span id="CommandRef"></span>
Line 299: Line 305:
From the AGDS documentation translated by Vassili Bykov, with additions/modifications by Claudio Matsuoka and XoXus (Last update 22 May 1999).
From the AGDS documentation translated by Vassili Bykov, with additions/modifications by Claudio Matsuoka and XoXus (Last update 22 May 1999).


<!-- XXXX -->
===Arithmetic commands===
===Arithmetic commands===