BYOND Environment This page contains an entry from the official DM Reference.


#define Name Value
#define Name(Parameters) Value


Name: A macro definition.
Value: The value to substitute for Name.
Parameters: Arguments to pass into the macro.


The #define statement creates a macro that is substituted for Name. Substitution only applies to whole words. Text inside of double or single quotes is not processed for substitution, so "This is BIG." would not be modified even if a macro named BIG were defined. That is different from "This is [BIG].", where BIG is an embedded expression, which does get processed for macro substitution.



#define DAY   0
#define NIGHT 1
var/daytime = NIGHT  //daytime = 1


#define SQR(X) ((X)*(X))
var/x = SQR(2)       //x = ((2)*(2)) = 4


Note that it's usually important to use parentheses around any arguments you use in a macro. Otherwise strange results may occur if you use an expression such as 2+3. In the SQR(X) example, if there were no parentheses around each X then the expansion of the macro would be (2+3*2+3). Since the * operator has a higher precedence than + the result is 11, not 25 as expected. It's equally important to put parentheses around the entire macro for the same reason.

See alsoEdit

directives #define | #error | #if | #ifdef | #ifndef | #include | #undef | #warn
macros DM_VERSION | __FILE__ | __LINE__ | __MAIN__
definitions DEBUG | FILE_DIR