Help with preprocessor macros.

Started by monkey0506, Mon 10/10/2005 04:56:22

Previous topic - Next topic

monkey0506

Seeing as my dialog system is now going to be released as three modules, I don't want to have to have a bunch of stuff that is used internally getting imported into every script (the stuff used for setting up the dialog text and user options).  So I figure, if I can put a preprocessor macro in there before the code I want to omit, and then remove it when I'm done with the code, it will free it up (as well as making dialog text readonly at runtime  :o).

I need to get to sleep, but I was messing around with it anyway and I can't seem to make it work...unless I put the macro definiton in a module defined before the module with the code I want to remove, then test it within the module, and remove it in a module after the module in question.  I have three modules...but I really shouldn't put the macro definition in the StrAdditions module as it's not at all related.

So...any help or suggestions?

Kweepa

I suggest you get this moved to the technical forum. :=
And maybe rephrase it a bit. I'm confused.
Still waiting for Purity of the Surf II

strazer

Also not sure what you want, so here a few things:

There is a built-in macro called "DEBUG" that is defined when the "Debug mode" is checked in the General settings and not defined if it is unchecked. So you could do:

Code: ags

// module header

#ifdef DEBUG // if debug mode on
  import bla Bla;
  #define SOMETHING 1
#endif

#ifndef DEBUG // if debug mode off
  import bla TheRealThing;
  #define SOMETHING 2
#endif


But ifdef and ifndef also work with self-defined macros:

Code: ags

// module header

#define RELEASE // comment this out to disable the enum below

#ifndef RELEASE
  enum Names {
    Otto, 
    Fred, 
    George
  };
#endif


Keep in mind that everything between ifdef resp. ifndef will be included or excluded in the compiled game. In the example above the Names will be picked up by the auto-complete even if RELEASE is defined.

Btw, you could use this to make your modules dependent on one another:

Code: ags

// module header: StrAdditions

#define StrAdditions_VERSION 100


Code: ags

// module header: ScrollingDialog

#ifndef StrAdditions_VERSION
  #error You need to import the StrAdditions module and place it before this one.
#endif


SMF spam blocked by CleanTalk