Difference between revisions of "Defines"
(Created page with "'''Defines''', in AGI logic, allow you to provide a proper name for the variables, flags, objects and other data in...") |
|||
(10 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | '''Defines''', in [[AGI|AGI]] [[Logic|logic]], allow you to provide a proper name for the [[Variable|variables]], [[Flag|flags]], [[Animated Object|objects]] and other data in the game. This significantly improves the readability of the code. | + | '''Defines''', in [[AGI|AGI]] [[Logic Resource (AGI)|logic]], allow you to provide a proper name for the [[Variable|variables]], [[Flag|flags]], [[Animated Object|objects]] and other data in the game. This significantly improves the readability of the code. |
+ | |||
+ | To create a define name, use the <code>#define</code> command. The name of the define is given, followed by the define value: | ||
− | |||
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
− | |||
<syntaxhighlight lang="agi"> | <syntaxhighlight lang="agi"> | ||
#define ego o0 | #define ego o0 | ||
#define roomDescription "This is a large hall with tall pillars down each side." | #define roomDescription "This is a large hall with tall pillars down each side." | ||
− | </syntaxhighlight | + | </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: | ||
+ | |||
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
− | |||
<syntaxhighlight lang="agi"> | <syntaxhighlight lang="agi"> | ||
draw(ego); | draw(ego); | ||
print(roomDescription); | print(roomDescription); | ||
− | </syntaxhighlight> | + | </syntaxhighlight> |
+ | |||
'''Note:''' The rules for defines vary depending on the compiler. The following discussion applies to the [[AGI Studio|AGI Studio]] compiler. | '''Note:''' The rules for defines vary depending on the compiler. The following discussion applies to the [[AGI Studio|AGI Studio]] compiler. | ||
Line 24: | Line 25: | ||
The define name can contain letters, numbers, and the characters '_' and '.'. Spaces are not allowed. | The define name can contain letters, numbers, and the characters '_' and '.'. Spaces are not allowed. | ||
− | == Example == | + | ==<br /> Example == |
+ | |||
+ | Below is a typical [[New Room Section|new room section]] of a logic file, without defines: | ||
− | |||
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
− | |||
<syntaxhighlight lang="agi"> | <syntaxhighlight lang="agi"> | ||
if (f5) | if (f5) | ||
Line 40: | Line 41: | ||
} | } | ||
− | </syntaxhighlight> | + | </syntaxhighlight> |
+ | |||
The same code, using defines, might appear like the following: | The same code, using defines, might appear like the following: | ||
+ | |||
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
− | |||
<syntaxhighlight lang="agi"> | <syntaxhighlight lang="agi"> | ||
#define new_room f5 | #define new_room f5 | ||
Line 58: | Line 60: | ||
show.pic(); | show.pic(); | ||
} | } | ||
− | </syntaxhighlight> | + | </syntaxhighlight> |
+ | |||
The AGI Studio compiler allows you to place the <code><nowiki>#define</nowiki></code> commands in a separate file and then use those defines in multiple logics without having to redefine them all again. See [[Includes|includes]] for more details. | The AGI Studio compiler allows you to place the <code><nowiki>#define</nowiki></code> commands in a separate file and then use those defines in multiple logics without having to redefine them all again. See [[Includes|includes]] for more details. | ||
− | == See also == | + | ==<br /> Sources == |
+ | |||
+ | * [[AGI Studio|AGI Studio]] help file | ||
+ | |||
+ | ==<br /> See also == | ||
* [[Logic Syntax|Logic syntax]] | * [[Logic Syntax|Logic syntax]] | ||
Line 67: | Line 74: | ||
* [[Includes|Includes]] | * [[Includes|Includes]] | ||
− | + | | |
− | + | [[Category:AGI Logic]] | |
− | + | [[Category:Variables]] | |
− |
Latest revision as of 13:57, 30 January 2024
Defines, in AGI logic, allow you to provide a proper name for the variables, flags, objects and other data in the game. This significantly improves the readability of the code.
To create a define name, use the #define
command. The name of the define is given, followed by the define value:
<syntaxhighlight lang="agi">
#define ego o0 #define roomDescription "This is a large hall with tall pillars down each side."
</syntaxhighlight>
Then the define name can be used in place of the define value:
<syntaxhighlight lang="agi">
draw(ego); print(roomDescription);
</syntaxhighlight>
Note: The rules for defines vary depending on the compiler. The following discussion applies to the AGI Studio compiler.
Define names can only be used in arguments of commands (including gotos and the v0 == 3
type syntax (some compilers may allow you to use them anywhere).
Defines must be defined in the file before they are used.
The define name can contain letters, numbers, and the characters '_' and '.'. Spaces are not allowed.
Example
Below is a typical new room section of a logic file, without defines:
<syntaxhighlight lang="agi">
if (f5) { load.pic(v0); draw.pic(v0); discard.pic(v0);
draw(o0); show.pic();
}
</syntaxhighlight>
The same code, using defines, might appear like the following:
<syntaxhighlight lang="agi">
#define new_room f5 #define room_no v0 #define ego o0
if (new_room) { load.pic(room_no); draw.pic(room_no); discard.pic(room_no);
draw(ego); show.pic(); }
</syntaxhighlight>
The AGI Studio compiler allows you to place the #define
commands in a separate file and then use those defines in multiple logics without having to redefine them all again. See includes for more details.
Sources
- AGI Studio help file
See also