NWN2 Scripting.




Simulation Training.

Introduction
Home
First Program
Seeing Results
Variables and Data Types
Comments
Functions
Data Conversion
Random Numbers
Concatenation
Arithmetic Operators
Compound Assignments
One More or Less
Precedence
Relational Operators
The Open Branch
The Closed Branch
Logical AND
Logical OR
Compound Statements
ELSE If
Switch Case
The ? Operator
The for Loop
The while Loop
The do while Loop
Introduction to Functions
Passing Values
Passing Multiple Values
Multiple Functions
Simplifying Functions
TRUE/fALSE Conditions
Return Values
Setting Global Variables
Getting Global Variables
Setting Local Variables
Getting Local Variables
WayPoints Introduction
Static Waypoint Sets
Dynamic Waypoint Sets
Dynamic WP Cycles
Input Output

Simplifying Functions

You can simplify the use of very complex functions by making a slight modification with them and then calling the function from antoher program. This becomes very helpful when you may use the same complex function several times and wish to only have a few changes in that function each time you call it. This section gives an example of doing just that.


Example Program

The following program shows the creation of an input box which is explained in this section: NWN2 Input/Output Input Box. It is saved as ta_msgbox. Note that hte function is of type void (meanign it will not return a value), and the argument is a data type string Message. Also note that the program itsefl is quite a large program. What we wish to do here is to simply change the message dispaleyd on the message box every time it is sued. This will be accomplisehd through the use of the single argument Message.


ta_msgbox

void MessageBox(string Message)

 {

 /*Player Object of the Player to show this Message Box.*/

 object oPC=GetPCSpeaker();

 //------------------------------

/*Message String Reference. Can be set to 0 if string Message is given a value.*/

 int MsgStrRef;

 //------------------------------

 /*The message that will appear on the Message Box.*/

 //Message;

 //------------------------------

 /*The program that will be called when the OK button is pressed. Must begin with gui_*/

  string OKCall;

 //------------------------------

 /*The program that iwll be called when the CANCEL button is pressed. Must begin with gui_*/

  string CanCall;

 //------------------------------

 /*If set to TRUE the CANCEL button will show in the Message Box.*/

  int ShowCan;

 //------------------------------

 /*The Name of the GUI to be used for the Message Box.*/

  string GUIType;

 //------------------------------

 /*Message String Reference for the OK button. Defaults to OK.*/

  int StrRefOK;

 //------------------------------

 /*The text to appear on the OK button.*/

  string OKStr;

 //------------------------------

 /*The String Reference for the CANCEL button. Defaults to CANCEL.*/

  int StrRefCan;

 //------------------------------

 /*The text to appear on the CANCEL button.*/

  string CanStr;

 //------------------------------

 /*The text will appear on the Input Field of the Message Box. Can be used as a Promt.*/

  string DeftStr;

 //------------------------------

 /*Doesn do anything right now.*/

  string VStr;

 //------------------------------

 

 MsgstrRef=0; //Not necessary, set to 0.

 OKcall="gui_input_ok"; //Program to be called when OK is pressed.

 CanCall="";//Program to be calld when CANCEL is pressed.

 ShowCan=TRUE; //Will show the CANCEL button.

 GUIType="SCREEN_STRINGINPUT_MESSAGEBOX"; //Type of GUI.

 strRefOK=0; //Not necessary, set to 0.

 OKStr="OKAY"; //String for the OK button.

 StrRefCan=0; //Not necessary, set to 0.

 CanStr="CANCEL"; //String for the CANCEL button.

 DeftStr="Plae input here."; //String for Input Box.

 VStr=""; //Does nothign for now.

 

DisplayInputBox(oPC, MsgStrRef, Message, OKCall, CanCALL, ShowCan, GUIType, StrRefOK, OKStr, StrRefCan, CanStr, DeftStr, VStr);

}

The following program calls the above function:

#include "ta_msgbox"

void main()

 {

  object oPC=GetEnteringObject();

 string TheMessage;

 string Firstname;

 FirstName=GetFirstName(oPC);

 TheMessage="Hello," + First Name + ", enter the secret word!";

 MessageBox(TheMessage);

}


The above program compiles. Note in the above program that the script ta_msgbox is first included. THe program then gets the name of the oPC and includes it in the string TheMessage. As an example, if the first name of the oPC were Elvewyn, then the message that would be dispaleyd on the message box would be: Hello, Elvewyn, enter the secret word!

As you can see from the above example, the process of using very complex and large scripts can be simplified through the process of using very complex and large scripts can be simplified through the use of modifying them by adding the arguments from the variables in those scripts that you wish to change every time you use them. In this case, the only variable we wished to change was the message that appeared on the message box script every time it was used.

Nwn2Scripting provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 2008 by Adamson House, Ltd. All Rights Reserved.

Questions or Comments: EMail Webmaster

Donations are to Adamson House, Ltd who maintains this site.
All donations go the the improvement of this site.