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

Return Values

Custom functiosn allow you to return values to the calling function. This is a very powerful feature which can be used in many ways. For example, this feature can be used to return a TRUE or False conditional in an conversation. An example of having a custom function return a value is shown here.


Returning a Value from a Custom Fuction

The NWN2 data type int allows for two special conditions. These are TRUe and FALSE (they must be all uppercase to work). The following program illustrates:


 int TestIt()

{

 object oPC=GetEnteringObject( );

 int Condition1;

 int Condition2;

 int HitPoints;

  HitPoints=GetCurrentHitPoints(oPC);

 Condition1=TRUE;

 Condition2=FALSE;

return (HitPoints>10)?Condition1:Condition2;

}

 


The above program compiles without errors. Important points of the above program are:

  • The custom function is of data type int. It is int Testit()
  • The custom function must be of the same data type as the data type that will be returned.
  • The custom function uses the C++ key word return.
  • The custom function will return either a TRUE or a FALSE to the caling function.
  • What is returned by this function will depend upon the current hit points of the creature.
  • If the hitpoints are greater than 10 a TRUE will be returned, otherwise a FALSE will be returned.

 

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.