First off, #define is a special keyword used in Global code only.
Define is a way to substitute aa string of characters everytime a word appears. In this regard, it is somewhat like a variable, and can be used as one. However, it is much more versatile than a variable.
To use #define, you go to the global code script, and type #define followed by a unique name, much as you would name a variable. Immediately after the name, you put the text that will be substituted every time GE sees the unique name.
You do not normally use a = sign immediately after the unique name. You do not normally use " marks around the text either. Note that you CAN use these. You can use any characters, but they are going to be inserted in the code, so be wary, you can cause errors. Also, dont end the line with ;
#define MAXINT 2147483647
Now say you are making a cheat code, and want to give the player the maximum amount of gold. Just use
player.gold = MAXINT;
That seems to be just like a variable, right? well, its not. Lets look at another example.
say you have this in your players code...
ChangeAnimationDirection("Event Actor", FORWARD);
Now thats kind of long, eh? Good thing makslane lets use select it from a menu, and has GE fill it in. A lot of people dont like how the edit window is limited in size. So we can do this:
#define CAD ChangeAnimationDirection
and write this into the players code....
CAD("Event Actor", FORWARD);
Lets shrink it a little further... Event Actor appears all over in scripts...
#define EA "Event Actor"
note the "" marks. You need them here.
CAD(EA, FORWARD);
See, Makslane used FORWARD as a define. Its good practice to use ALLCAPS for letters in define keywords. Still, lets reduce it further.
#define FORWARD FWD
and our final line becomes...
CAD(EA,FWD);
compared to the original...
ChangeAnimationDirection("Event Actor", FORWARD);
Its about 1/3 as long, and still somewhat readable. It saves script window line space and program size, if you substitute words that are used lots, like "Event Actor".
So thats pretty cool, I think. Still, there is more that you can do..
#define INVISIBILITY power*skill-rainlevel-noise+blindness
Note the lack of =.
Now everywhere you use INVISIBILTY, the formula gets inserted and calculated. Lets see a variable do THAT!
Please share with us other uses you have found for #define!