| 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 FunctionsYou 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.
The following program calls the above function:
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.
|
|