ID:152932
Jul 5 2005, 8:46 am
|
|
what is #define what are it used for i know you use #define to link files but i've seen people use it to replace var when should you use it in place of a var, and why would you want to?
|
I barely use it, the only thing I really use it for is defining new layers and special colors.
(ie: NPC_COLOR TEXT_COLOR ERROR_COLOR PARTY_COLOR etc.) |
In response to Loduwijk
|
|
so it's kind of like a var with and absolute value? or something to that effect?
|
In response to tidus123
|
|
it's a constant variable that can't be accessed in the games. It's sometimes good to define things because it's a quick way to change major values in the game.
|
In response to Dark Weasel
|
|
Of course, you can often use constant variables for the same effect. =)
var/const/MAX_LEVEL = 99 vs.
#define MAX_LEVEL 99
You can also define macros in place of simple functions.: #define srchasitem(itemtype) (locate(itemtype) in src) Don't overuse macros, though, because they can get ugly quickly. Especially since they're invisible at runtime, making them harder to debug than ordinary procs. And, of course, macros can't take advantage of object-oriented features (they can't be defined on specific objects). |
#define DEFINITION value
Everywhere in your code that the compiler sees DEFINITION, it will compile it as if value were there instead.
When the compiler looks at that, the #define statement tells it to treat MAX_LEVEL as the number 99, therefor, when the code gets compiled, the compiler sees the following.