by Fuzzy » Sat Feb 24, 2007 10:43 pm
Yes, define is more than storage for values of strings. You can use it to store portions of code. That code will go uncompiled at first..
#define HEAL Hp+amount, MaxHP
then later in code...
amount = rand(10);
hp = min(HEAL);
you can see that it can act somewhat like a function, without the overhead of the function. It stores the formula and nothing more. You dont have to remember what arguments to pass it. You could also wrap the min() around the contents of HEAL.
Note that convention says use capital letters for define labels, and that the line is not normally appended with ; but it is legal.
one interesting use is to shorten key words...
#define GaAiC getAllActorsInCollision
#define EA "Event Actor"
later in code...
GaAiC(EA,&num);
thats kinda silly, but shows how you can compress your code. If you use certain long key words repeatedly, you can actually shorten up your code considerably.
From my experiments, it extends to the compiled program too. however, you might find that it slows things down a bit. Makslane will know better than I.
Mortal Enemy of IF....THEN(and Inspector Gadget)
Still ThreeFingerPete to tekdino