FANDOM


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

FormatEdit

#define Name Value
#define Name(Parameters) Value

ArgsEdit

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

DescriptionEdit

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.

ExamplesEdit

ExampleEdit

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

ExampleEdit

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

ParenthesesEdit

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


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