Constants
A constant is a symbol (or label) to represent a value that should not change during program execution (traditionally constants are symbols that are replaced by the precompiler with their actual values - or constant definition - before compiling).
Constants are a great way to make code more readable and much easier to maintain. Also it is useful when a value may change at some point; one can simply change the constant's definition once without having to change the value throughout all the source code and recompile.
In NWNScript, constants are just variables with a different naming convention: use all capital letters and place underscores to separate words.
int DAYS_IN_A_YEAR = 365;
Although it would seem that NWNScript doesn't support true constants in the sense, there is a way to cheat and provide your own constants, although this is not recommended. If you place your variable declarations and values in \override\nwscript.nss, they function as real constants and can be used in case statements within switch statements. If you used this method, you would have to distribute your \override\nwscript.nss script with any modules you wrote (if you're releasing the source code), and risk incurring version problems if BioWare updates the script in later versions of NWN. You cannot use variables as the test portion of a case within a switch statement, as they are not true constants, so being able to define constants is plainly an advantage that we do not have.
author: Charles Feduke, additional contributor(s): Iskander Merriman, David Delmont
Send comments on this topic.