lfnetwork.com mark read register faq members calendar

Thread: Introduction to Scripting Syntax
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 01-25-2005, 04:59 AM   #1
Well past expiration date
tk102's Avatar
Join Date: Jan 2004
Posts: 5,768
Current Game: FTL
10 year veteran!  Forum Veteran  Helpful!  Notable contributor 
Introduction to Scripting Syntax

Here is a very brief introduction into scripting syntax. For those of you who have programmed in C, you will find scripting syntax very familiar.

The primary game functions are all defined in nwscript.nss along with most of the useful game variables. You will often refer to nwscript.nss as you begin scripting.

If you haven't had any programming experience, scripting may look intimidating. Don't worry. KotOR provides numerous source files (.nss) within scripts.bif that you can look at for examples. After awhile, you will begin to see the patterns of how functions are called and how variables are used.

Variable declaration and intialization
Note the use of the equals sign and no paranthesis.
int DISGUISE_TYPE_TURRET          = 182;
^   ^                               ^
|   |                               |-the value to which the variable is set
|   |-the variable
|-the data type of the variable (integer)
Function declaration
Paranthesis present, equals sign absent
object CreateItemOnObject(string sItemTemplate, object oTarget, int nStackSize);
^      ^                  ^                     ^               ^
|      |                  |                     |               |- an integer parameter  
|      |                  |                     |- an object parameter
|      |                  |-a string parameter
|      |-the function
|-data type of what the function returns (an object)
Data types

Basic data types:
  • int integer (eg.: 8) also used for boolean operations
  • float floating point (eg.: 3.14)
  • string text string (eg.: "Hello world")

Complex data types:
  • object Special data type for referencing in-game objects
  • effect Special data type for referencing in-game effects
  • vector a bundle of 3 floats (x, y, z, coordinates)
  • location a vector bundled with a float (orientation)
  • talent Special data type for referencing a feat, skill, or spell (rare)
More info concerning data types available at: NWNLexicon's page

  1. All parentheses (), brackets[], and braces{} must be used in a pair.
  2. Statements that do not open braces must end with a semicolon.
  3. Scripts must have a void main() function or int StartingConditional() function or they will not be compiled into an .ncs
  4. All functions and variables must be declared.
  5. KotOR1 and KotOR2 have different nwscript.nss files that define their functions. You should not expect an .ncs from one game to work in the other.
  6. Data types are strict meaning you cannot put an integer value into a float variable for example.
  7. Indentation and line breaks are purely for the benefit of the programmer.

Operators (same as C programming)
Arithmetic: + - * /
Modulus: % the remainder, for integers only (eg. 5%2==1)
Assignment = don't confuse with equality!
Increment ++ x++ is the same as x=x+1
Assign and increment += x+=2 is the same as x=x+2

Equality ==
Inequality !=
Greater than >
Greater than or equal to >=
Less than <
Less than or equal to <=

Logical AND &&
Logical OR ||
Logical NOT !

Single line comment indicator //
Multi-line comment begin indicator /*
Multi-line comment end indicator */

Last edited by tk102; 01-25-2005 at 12:52 PM.
tk102 is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > Star Wars Gamer > Community > The Star Forge > Knights of the Old Republic series > Holowan Laboratories > Tutorials > Tutorials: Scripting > Introduction to Scripting Syntax

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -4. The time now is 10:09 AM.

Powered by vBulletin®
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.