Open main menu

Difference between revisions of "AGIWiki/Defines"

No change in size ,  20:50, 11 May 2016
Fix syntax highlighting
(Created page with "{{AGIWiki}} '''Defines''', in AGI logic, allow you to provide a proper name for the variables, flags, [[A...")
 
(Fix syntax highlighting)
Line 3: Line 3:
'''Defines''', in [[AGIWiki/AGI|AGI]] [[AGIWiki/Logic|logic]], allow you to provide a proper name for the [[AGIWiki/Variable|variables]], [[AGIWiki/Flag|flags]], [[AGIWiki/Animated object|objects]] and other data in the game. This significantly improves the readability of the code.
'''Defines''', in [[AGIWiki/AGI|AGI]] [[AGIWiki/Logic|logic]], allow you to provide a proper name for the [[AGIWiki/Variable|variables]], [[AGIWiki/Flag|flags]], [[AGIWiki/Animated object|objects]] and other data in the game. This significantly improves the readability of the code.


To create a define name, use the <syntax type="C++">#define</syntax> command. The name of the define is given, followed by the define value:
To create a define name, use the <source lang="cpp">#define</source> command. The name of the define is given, followed by the define value:
<syntax type="C++">
<source lang="cpp">
  #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."
</syntax>
</source>


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:
<syntax type="C++">
<source lang="cpp">
  draw(ego);
  draw(ego);
  print(roomDescription);
  print(roomDescription);
</syntax>
</source>
'''Note:''' The rules for defines vary depending on the compiler. The following discussion applies to the [[AGIWiki/AGI Studio|AGI Studio]] compiler.
'''Note:''' The rules for defines vary depending on the compiler. The following discussion applies to the [[AGIWiki/AGI Studio|AGI Studio]] compiler.


Line 25: Line 25:


Below is a typical [[AGIWiki/New room section|new room section]] of a logic file, without defines:
Below is a typical [[AGIWiki/New room section|new room section]] of a logic file, without defines:
<syntax type="C++">
<source lang="cpp">
  if (f5)
  if (f5)
  {
  {
Line 36: Line 36:


  }
  }
</syntax>
</source>
The same code, using defines, might appear like the following:
The same code, using defines, might appear like the following:
<syntax type="C++">
<source lang="cpp">
  #define new_room f5
  #define new_room f5
  #define room_no  v0
  #define room_no  v0
Line 52: Line 52:
     show.pic();
     show.pic();
  }
  }
</syntax>
</source>
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 [[AGIWiki/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 [[AGIWiki/Includes|includes]] for more details.


TrustedUser
2,147

edits