ID:152686
 
Well I've been curious as to how #define works. Can someone explain it a little bit? I've seen some of how to use it around on the forums. I still don't get it,
I've tried
#define Fireball "/obj/Fireball"

Is this possible to set a word to a path or not? Should I just use variables that are defined at world start up?
#define replaces the word you have defined to what you define it to.

For example:
#define fireball /obj/fireball

proc/create_fireball(turf/loc)
if(isturf(loc))
new fireball(loc)


Gurus correct me if I'm wrong.
When you compile your code, any instances of the defined word get replaced with what it is defined as. So:

#define MESSAGE "Hello, world"

mob/Login()
..()
world << MESSAGE


Compiles the same way as:

mob/Login()
..()
world << "Hello, world"


You can define something as anything, so:

#define TEST alfaslgjalgjaljgalgj


would compile, but if you actually USED the TEST define, you'd probably get interesting syntax errors.
In response to Jp
Ah..
I'll do some testing =)
In response to Joseph Constantine
Wow. Thanks everyone. this will really help in compacting my code. >=D

ok wait. xD
I've got
#define FireLO "/obj/Attack/Missile/Fire/FireBall"
mob/verb
FireBall()
set category = "ATTACK"
if(usr.Action && usr.InBattle && MPChecker(1))
view(30) <<" FireBall! ([usr])"; Fire(0, "[FireLO]")
else return

It gives me a error: undefined variable.
In response to Mechanios
If you are defining a type path, you REALLY shouldn't be using quotation marks around it. But, when you define something it isn't a variable. You simply type it what you defined it as.


#define FireLO /obj/Attack/Missile/Fire/FireBall
mob/verb
FireBall()
set category = "ATTACK"
if(usr.Action && usr.InBattle && MPChecker(1))
view(30) <<" FireBall! ([usr])"; Fire(0, FireLO)
else return