Technical Glossary: Constant

A constant is an identifier which has a value that can not change at runtime.

This can certainly be directed toward many purposes, but the overwhelming majority of use of constants is to provide a human-readable name for something that needs to be stored and referenced as a number. This makes it easier to talk about, reference, and write with these structures. When such is used by scripters or developers, these numbers are typically written out all together with a clear human-readable name, and then assigning it the value that the underlying data structure understands. It is then used like a variable (e.g. writing code with SKILL_PARRY instead of 10), and is then automatically compiled as its cheaper/smaller integer form.

This is typically made necessary by features which are designed to be expanded or configured, or by cases where storage/retrieval is faster or more efficient if the data is stored and handled as numbers, and only translated to human-readable output when displaying for human consumption. Examples of things that are actually integers would be skills, feats, spells, cleric domains, visual effects, or character classes. Examples of things that are not referenced by constants would be items (not item properties or base item types-- the items themselves), areas, or waypoints.

When used by builders, it often becomes necessary to learn a constant's value, due to things like the conversation editor not accepting constants by their names. These are typically stored in include files, such as nwscript.nss (which is present in every module, and contains constants defined by OE), acr_i.nss (which contains many constants which are specific to the ACR), or dmfi_inc_const.nss (which contains many constants which are specific to dmfi tools). You can read the lines of these files to learn what to place into a script that expects one of these constants. For instance, line 148 of acr_i contains this line:

const int SKILL_DECIPHER_SCRIPT = 32;

This tells you that, if you needed to refer to decipher script in a place that only accepts a number, that number would be 32.