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
tk102
Well past expiration date
 
tk102's Avatar
 
Join Date: Jan 2004
Posts: 5,766
Current Game: Dragon Age: Origins
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.
Code:
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
Code:
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

Rules
  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 > Knights of the Old Republic > Editing / Modding > Holowan Laboratories > 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 05:00 AM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.