Coding Standards
http://www.nwnlexicon.com/compiled/prim ... dards.html
http://www.nwnlexicon.com/compiled/prim ... tions.html
Constants should be entirely uppercase to easily distinguish them from variables.
Script Header Template
This is a sample header template to be used at the top of all custom scripts. For the sake of consistency and to make sure we organize the information in scripts the proper way, we all need to use one. The top half can be used in comment areas of NWN objects as well particularly if the object requires setup or contains configuration information for any system we're building that we need to explain.
Code: Select all
////////////////////////////////////////////////////////////////////////////////
//
// System Name : name of the system or NWN object the script pertains to
// Filename : name of the script file
// $Revision:: $ current version of the file
// $Date:: $ date the file was created or modified
// Author : name of the person who authored the script or changes to it
//
// Var Prefix: unique name comprised of 3 letter system and feature acronyms
// Dependencies: external object dependencies outside of nwscript
//
// Description
//
// Revision History
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Includes ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constants ///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Structures //////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Global Variables ////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function Prototypes /////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function Definitions ////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Function Prototyping
All functions need to be prototyped. This means they are listed in the appropriate section of the script and can be referenced by any function in that file or outside it. A brief explanation of the function's purpose followed by an explanation of all function arguments and return values should exist in comments directly above the function. Function arguments should be described in terms of what they represent and the range of values they can hold, where appropriate. This will allow any user in the toolset to simply double click on the function name and understand how the function should be used.
Example:
// This function determines if oObject has at least one level of sClassName
// sClassName is a case sensitive text representation of the class
// oObject is the creature to be examined
// Return Values:
// 0 - creature does not have any levels of the class
// 1 - creature has at least one level of the class
int HasClass(
string sClassName,
object oObject);
Local & Global Definitions
Local constants and functions should be defined in the file that requires them.
Global constants and functions (shared among multiple modules) should be defined in a "library" file which can be included by whatever script requires them.
Library files (non executables) containing constants, functions, and other definitions should be tagged with "
_i".
Public & Private Access
All access to data (variables, constants, etc) or functions is assumed to be public unless prefixed with an underscore ("
_") character. Information that is public can be accessed by anyone from any file or function. Information that is private should not be accessed by anyone from any file or function outside of the system it's used in. The intent here is to prevent intermediary functions and variables from being misused or corrupted through inappropriate invocations.
Modularity
All systems need to be designed for modularity. This means that systems must be self-contained, must preserve their interfaces across version updates, and be as independant of other systems as possible.