ID:152932
 
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?
#define is a command to the compiler, telling it how to compile whatever it is that you specify. The name of the definition gets replaced with the value.
#define DEFINITION value

Everywhere in your code that the compiler sees DEFINITION, it will compile it as if value were there instead.
#define MAX_LEVEL 99

mob/proc/level_up()
if(level >= MAX_LEVEL)return
level+=1

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.
mob/proc/level_up()
if(level >= 99)return
level+=1
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)

mob/verb/DoIHaveCheese()
if (srchasitem(/obj/item/cheese))
src << "CHEEEEEEEESE!"


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).