| 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 |
Passing Values The next section on Functiosn shows you how to make your custom functiosn even more powerful through the passing of parameters. These act like information messages to make your custom functions preform different tasks.
Creating a Function for getting Values The following program illustrates a function that can receive values. ta_speak
The above custom function (saved as ta_speak) has a variable of type string declard within its parenthesizes. The identifier used for this variable is Spoken. It is important to note that this variable Spoken will e used in the NWN2 function FloatingTextStringonCreature. When this function is used (called) by antoher program, the string entered for Spoken will be passed on to the body of this function to the NWN2 function FloatingTextStringonCreature. This is illustrated in the following program:
Observe in the above program that the custom function SayIt now has a string passed to it "Passed from a function". This string will now be passed on to the custom function (ta_speak) here, in that function, it will be passed down to the NWN2 function FloastingTextStringOnCreature. The above program will now cause the text Passed from a function to appear over the head of the PC Terminology There is some important terminology used in C++ for functiosn that pass values. These are listed below:
In our example, the decalred variable Spoken is a parameter for the custom function SayIt. The calling program (void main) uses the argument "Passed from a function".
In the next section ou will see how to create custom functiosn which contain more than one parameter allowing the calling program to pass more than one argument. This feature give sthe programmer a powerful option in the creation of custom functions.
|
|