const

From NWN Lexicon
Jump to: navigation, search

An unchanging value, usually an integer. Used in place of "magic numbers" to make code more readable.

Many constants have already been defined in the base game. For a list, see Category:Constants.

Remarks

Only int, string, and float data types may be used as constants.

Constants must be defined in the global scope (i.e., outside of any function, void main(), or int StartingConditional()).

It's recommended that constants be in all caps, with underscores instead of spaces. This helps people reading your script to quickly tell which values are constants and which are variables.

Example

// Defining a constant
const string MY_MESSAGE = "This string was defined in a constant!";
 
void main()
{
    // Using a constant in code
    SpeakString(MY_MESSAGE);
}

See Also