#define name

Defines the name as a condition for later including or excluding lines (see #ifdef), or for setting other special conditions during compilation.


#define TEST
#ifdef TEST
printf("This is a test!");

#define name value

Every time the name appears in the script below the #define, it will be replaced by the value, which can be another name, a number, or a simple arithmetic expression. Replacing names makes functions more 'readable', for instance by giving the entities' general purpose skill parameters some meaningful names.


#define PI 3.14159
#define HEALTH skill17
#define WINAPI __stdcall
x = 2.0*PI;
my.HEALTH -= 50;

long WINAPI MessageBox(HWND,char *,char *,long);


#undef name

Undefines a previously defined name.

#define macro(parameter,..)  expression(parameter,..)

Defines a macro as a replacement or abbreviation for a numerical expression. Whenever the macro is encountered in the code, the expression is executed. Macros work rather like functions, but with some minor differences. Since macros are implemented as a textual substitution, there is no effect on program performance (as with functions), however they produce larger code than functions. They are normally only used for fairly small expressions.

Examples (from acknex.h):

#define set(obj,flag) obj.flags |= (flag)
#define reset(obj,flag) obj.flags &= ~(flag)
#define toggle(obj,flag) obj.flags ^= (flag)
#define is(obj,flag) (obj.flags & (flag))
#define zero(ptr) memset((void*)&ptr,0,sizeof(ptr))

#define macro(parameter,..)  expression(parameter##token,..)

The merging operator ## adds the token to the parameter. Useful for redefining variable or functions names in a macro.


#define merge3(name) merge(name##1,name##2,name##3) // merge3(test) is evaluated to merge(test1,test2,test3) 


Some special #defines:


Initializes all local variables to 0. This makes function execution a little slower, but gives all variables a fixed starting value. Good for quick testing whether a random problem is related to an uninitialized local variable.


Switches off the lite-C pointer autodetection, and treats pointers as in C/C++. The address operator (&) must be used for passing addresses to functions, and the -> operator must be used for elements of a struct pointer. Otherwise a syntax error will be issued.

#define PRAGMA_API  FunctionName;ModuleName!ProcName

Loads the function prototype FunctionName from function ProcName in the DLL ModuleName (see Using DLLs). Example:
#define PRAGMA_API MessageBox;user32!MessageBoxA

#define PRAGMA_PLUGIN "dllname";

A7.10 Opens a DLL plugin with the given name located in the work folder or in a path relative to the work folder (plugins in the default folder PLUGINDIR are automatically opened). Plugin functions and engine extensions are available afterwards. PRAGMA_PLUGIN is only evaluated during compilation , and is only used for engine plugins, not for general DLLs. In a published project, all plugin DLL files are expected in the PLUGINDIR folder, and all other DLLs either in the application folder or in the Windows DLL path. Example:
#define PRAGMA_PLUGIN "dlls\\driver.dll";

#define PRAGMA_PRINT "text";

Displays the given text in the engine startup window when the compiler reaches this line. Useful to give engine startup messages or to find out at which position the compiler crashes when a damaged file is loaded during the compile process. Example:
#define PRAGMA_PRINT "\nThis is a compiler message!";

#define PRAGMA_PATH "path";

A7.10 Looks for include and other files in the given path when they are not found in the current folder. This is similar to the PATH statement in a project file, with the exception that paths given by PRAGMA_PATH are also used for include files. Example:
#define PRAGMA_PATH "%EXE_DIR%\Map-Editor\Scripts";


#define PRAGMA_LEVEL "levelname";

All entities from the given WMP file are automatically included into the published game folder or resource. Use this to make sure that all sub-entities of levels or map entities are included. Example:
#define PRAGMA_LEVEL "level2.wmp"; // include all entities from level 2

#define PRAGMA_BIND "filename";

The given file will be copied to the game folder by WED's Publish function, and/or included in the game resource. You do not need this statement when the file name is used in double quotes in the script, or when the file is a part of a level given with the PRAGMA_LEVEL statement. Example:
#define PRAGMA_BIND "model.mdl"; // The model.mdl file is included in the game folder and resource

See also:

#ifdef, #ifndef, #else, #endif, macros

► latest version online