NWScript
Encyclopedia
NWScript is the scripting language
developed by BioWare
for the computer role-playing game Neverwinter Nights
. It is based on the C programming language
and is implemented in the Aurora toolset
. Neverscript, an open source
3rd party editor, has been created for the Mac OS X
and Linux
versions of NWN because the Aurora toolset has not been ported
to those platforms.
NWScript is also used in the video games The Witcher, Star Wars: Knights of the Old Republic
and Star Wars: Knights of the Old Republic II The Sith Lords, which use the Odyssey Engine
. Neverwinter Nights 2
, the sequel
to the original NWN, features a modified version of this scripting language.
and binary
/ ternary
operators and some mathematical functions
. Function source code
is not accessible to the end-user, but the correct syntax
is defined in a script file called nwscript.nss. The users can create their own functions
, and these can be included in other scripts through the #include
directive
, which works slightly differently than in C++
.
" example message. This script puts a "Hello world" message in the player's message log. For it to work, it should be placed in the OnClientEnter event
of the module's
properties
.
The first line is the void main function
which is the function that a NWScript will start at. In the third line, the text Hello world is sent to the player's in-game message log.
, but not objects
. The following common data type
s are available in NWScript:
NWScript has also introduced some data types for purposes of the Neverwinter Nights game:
, the Aurora Toolset saves the plain text of the script as a file with a .nss filename extension
. When compiling
the script, a .ncs containing Bytecode
to be run on the NWScript Virtual Machine
file is created. If turned on, a debug
information file with an .ndb extension is also created. The game uses only the .ncs file (and the .ndb file if called).
When saving the created module, the files are packed into a single module file with a .mod extension, along with other information about the layout of the module.
Scripting language
A scripting language, script language, or extension language is a programming language that allows control of one or more applications. "Scripts" are distinct from the core code of the application, as they are usually written in a different language and are often created or at least modified by the...
developed by BioWare
BioWare
BioWare is a Canadian video game developer founded in February 1995 by newly graduated medical doctors Ray Muzyka, Greg Zeschuk, and Augustine Yip. BioWare is currently owned by American company Electronic Arts...
for the computer role-playing game Neverwinter Nights
Neverwinter Nights
Neverwinter Nights , produced by BioWare and published by Infogrames , is a third-person perspective computer role-playing game that is based on third edition Dungeons & Dragons and Forgotten Realms rules. It was originally to be published by Interplay Entertainment, but the publisher's financial...
. It is based on the C programming language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
and is implemented in the Aurora toolset
Aurora toolset
The Aurora toolset is a set of software tools developed by BioWare for use with the Aurora Engine, the game engine first used in BioWare's 2002 computer role-playing game Neverwinter Nights...
. Neverscript, an open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
3rd party editor, has been created for the Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
and Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
versions of NWN because the Aurora toolset has not been ported
Porting
In computer science, porting is the process of adapting software so that an executable program can be created for a computing environment that is different from the one for which it was originally designed...
to those platforms.
NWScript is also used in the video games The Witcher, Star Wars: Knights of the Old Republic
Star Wars: Knights of the Old Republic
Star Wars: Knights of the Old Republic is a role-playing video game developed by BioWare and published by LucasArts. It was released for the Xbox on July 15, 2003, for Microsoft Windows on November 19, 2003, and on September 7, 2004 for Mac OS X. The Xbox version is playable on Xbox 360 with its...
and Star Wars: Knights of the Old Republic II The Sith Lords, which use the Odyssey Engine
Odyssey Engine
The Odyssey Engine is a computer game engine developed by BioWare and has exclusively been used to create three dimensional computer role-playing games...
. Neverwinter Nights 2
Neverwinter Nights 2
Neverwinter Nights 2 is a computer role-playing game developed by Obsidian Entertainment and published by Atari. It is the sequel to BioWare's Neverwinter Nights, based on the Dungeons & Dragons pencil and paper fantasy role-playing game...
, the sequel
Sequel
A sequel is a narrative, documental, or other work of literature, film, theatre, or music that continues the story of or expands upon issues presented in some previous work...
to the original NWN, features a modified version of this scripting language.
Syntax
While based on C, NWScript does not have many functions from the C family, excluding logicalLogical connective
In logic, a logical connective is a symbol or word used to connect two or more sentences in a grammatically valid way, such that the compound sentence produced has a truth value dependent on the respective truth values of the original sentences.Each logical connective can be expressed as a...
and binary
Binary operation
In mathematics, a binary operation is a calculation involving two operands, in other words, an operation whose arity is two. Examples include the familiar arithmetic operations of addition, subtraction, multiplication and division....
/ ternary
Ternary operation
In mathematics, a ternary operation is an n-ary operation with n = 3. A ternary operation on a set A takes any given three elements of A and combines them to form a single element of A. An example of a ternary operation is the product in a heap....
operators and some mathematical functions
Function (mathematics)
In mathematics, a function associates one quantity, the argument of the function, also known as the input, with another quantity, the value of the function, also known as the output. A function assigns exactly one output to each input. The argument and the value may be real numbers, but they can...
. Function source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...
is not accessible to the end-user, but the correct syntax
Syntax of programming languages
In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language. The syntax of a language defines its surface form...
is defined in a script file called nwscript.nss. The users can create their own functions
Subroutine
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....
, and these can be included in other scripts through the #include
Header file
Some programming languages use header files. These files allow programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers...
directive
Directive (programming)
In computer programming, the term directive is applied in a variety of ways that are similar to the term command. It is also used to describe some programming language constructs ....
, which works slightly differently than in C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
.
Hello world
NWScript has no way to directly target the screen for output. Instead, for instance, in-game characters such as the player character can be made to speak the typical "Hello worldHello world program
A "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...
" example message. This script puts a "Hello world" message in the player's message log. For it to work, it should be placed in the OnClientEnter event
Event-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...
of the module's
Adventure (role-playing games)
An adventure is either a published or otherwise written collection of plot, character, and location details used by a gamemaster to manage the plot or story in a role-playing game. Each adventure is based upon a particular gaming genre and is normally designed for use with a specific game or gaming...
properties
Property (programming)
A property, in some object-oriented programming languages, is a special sort of class member, intermediate between a field and a method. Properties are read and written like fields, but property reads and writes are translated to get and set method calls...
.
The first line is the void main function
Subroutine
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....
which is the function that a NWScript will start at. In the third line, the text Hello world is sent to the player's in-game message log.
Data types
NWScript allows structsObject composition
In computer science, object composition is a way to combine simple objects or data types into more complex ones...
, but not objects
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
. The following common data type
Data type
In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...
s are available in NWScript:
- integer (int)IntegerThe integers are formed by the natural numbers together with the negatives of the non-zero natural numbers .They are known as Positive and Negative Integers respectively...
- float
- stringString (computer science)In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set or alphabet....
- structObject compositionIn computer science, object composition is a way to combine simple objects or data types into more complex ones...
NWScript has also introduced some data types for purposes of the Neverwinter Nights game:
- object (refers to game objects, such as NPCsNon-player characterA non-player character , sometimes known as a non-person character or non-playable character, in a game is any fictional character not controlled by a player. In electronic games, this usually means a character controlled by the computer through artificial intelligence...
and placeable objects). - location (refers to the in-game location of an object, consisting of an area object reference, a vector and a float describing the position and facing within the area).
- talent (refers to spellsMagic (paranormal)Magic is the claimed art of manipulating aspects of reality either by supernatural means or through knowledge of occult laws unknown to science. It is in contrast to science, in that science does not accept anything not subject to either direct or indirect observation, and subject to logical...
and abilities). - vector (refers to coordinatesCoordinate systemIn geometry, a coordinate system is a system which uses one or more numbers, or coordinates, to uniquely determine the position of a point or other geometric element. The order of the coordinates is significant and they are sometimes identified by their position in an ordered tuple and sometimes by...
of an object, and is a construct of three floats). - itemproperty (refers to abilities on items such as weaponWeaponA weapon, arm, or armament is a tool or instrument used with the aim of causing damage or harm to living beings or artificial structures or systems...
s for use in the game). - effect (refers to game-mechanics-altering effects on objects; for example effects created by spells, diseases, and displayed visual effects).
File format
When saving a scriptScripting language
A scripting language, script language, or extension language is a programming language that allows control of one or more applications. "Scripts" are distinct from the core code of the application, as they are usually written in a different language and are often created or at least modified by the...
, the Aurora Toolset saves the plain text of the script as a file with a .nss filename extension
Filename extension
A filename extension is a suffix to the name of a computer file applied to indicate the encoding of its contents or usage....
. When compiling
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...
the script, a .ncs containing Bytecode
Bytecode
Bytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...
to be run on the NWScript Virtual Machine
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...
file is created. If turned on, a debug
Debugging
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected. Debugging tends to be harder when various subsystems are tightly coupled, as changes in one may cause bugs to emerge...
information file with an .ndb extension is also created. The game uses only the .ncs file (and the .ndb file if called).
When saving the created module, the files are packed into a single module file with a .mod extension, along with other information about the layout of the module.
External links
- BioWare NWN Scripting Forum – BioWare's dedicated forum for scripting discussion.
- NWN Lexicon – A database of scripting functions and tutorials.
- Lilac Soul's NWN Script Generator – A popular utility to automatically generate NWscript code.