Constants

From ZDoom Wiki

Jump to: navigation, search

Constants are values that are always the same when executed. An example of a constant would be 1, "Hello", etc. Constants can also be #define'd

The syntax of defining a constant is as follows

#define NAME VALUE

Numbers

These constants can be used as values and also as script numbers

For example (This does compile)

#define SNUM 1
#define VAL 3131
script SNUM (void)
{
    int x = VAL;
}

Here SNUM would be replaced with 1 and VAL would be replaced with 3131.

This is useful for a constant that is used a lot. If something like the spawn numbers were to be changed, you'd only need to change the constant for the defined spawn numbers.

String Constants

You can define string constants as well.

1

script 1 open
{
    print(s:"err");
    print(s:"err");
}

2

#define STR_err "err"
script 1 open
{
    print(s:STR_err);
    print(s:STR_err);
}

Examples 1 and 2 produce identical output.

Personal tools