Constants
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.
Library Constants
You can also place constants in your Libraries. This can be especially useful when, say, applying a TID to the player, or numbers you may want handy for custom functions.
The syntax is much the same as a normal constant, with one change.
#libdefine NAME VALUE
Here is an example of some constants I personally use. These constants provide quick shortcuts to cardinal directions for PolyObjects and SetActorAngle.
#libdefine POLY_UP 64 #libdefine POLY_DOWN 192 #libdefine POLY_LEFT 128 #libdefine POLY_RIGHT 0 #libdefine ACTOR_FACE_UP 0.25 #libdefine ACTOR_FACE_LEFT 0.5 #libdefine ACTOR_FACE_RIGHT 1.0 #libdefine ACTOR_FACE_DOWN 0.75