Defines the name as a condition for later including or excluding lines (see #ifdef),
or for setting other special conditions during compilation.
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);
#defines are valid within all subsequent C code, but ignored in
script parts that are not C standard, such as effect code or
engine objects definitions like PANEL*, MATERIAL* etc.
The same name or macro can be defined several times, in order to give it different values for different parts of the code. Only the last #define before a code line has an effect on that line.
#defines are only evaluated during compilation.
Thus they can't be changed anymore in a published project.
#define lines normally don't end with a semicolon, unless you want value to end with a semicolon for some reason. Some PRAGMA defines (see below) require a semicolon for ending a text string.
- As a convention, defined names are normally written in uppercase.
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!";
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.
#define PRAGMA_PATH "%EXE_DIR%\Map-Editor\Scripts";
- Paths will be searched in the given sequence. They are relative to the current work folder. In order to be able to copy your project to different locations, use relative paths for all files belonging to your project, and absolute paths for all files that are on an absolute location on your hard disk (like template scripts).
- If the path begins with "%EXE_DIR%", it's a subfolder of the program folder (like "%EXE_DIR%\templates\images"). Apart from that, do not use special characters or spaces in your folder names.
- Theoretically you can specify up to 32 PATH names, but it's better to stay well below that limit. Each folder is searched in sequence until a given file is found, so having lots of paths can increase the project startup time.
PRAGMA_PATH is only evaluated during compilation. In a published project, all files are placed in the project folder by default. For using subfolders in a published project, either add them at runtime through add_folder(), or use a .wdl project file.
- Paths can be read by external applications through the pPaths array.
Paths, just like variables, file or object names, must not contain spaces.
#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
#ifndef, #else, #endif, macros