Open main menu

AGIWiki/Defines

< AGIWiki
Revision as of 15:17, 25 October 2018 by Criezy (talk | contribs) (Text replacement - "</source>" to "</syntaxhighlight>")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
AGIWiki


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:

 #define ego o0
 #define roomDescription "This is a large hall with tall pillars down each side."

Then the define name can be used in place of the define value:

 draw(ego);
 print(roomDescription);

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:

 if (f5)
 {
   load.pic(v0);
   draw.pic(v0);
   discard.pic(v0);

   draw(o0);
   show.pic();

 }

The same code, using defines, might appear like the following:

 #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();
 }

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.

See also

Sources