| 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 |
Introduction to FunctionsFunctions are sectiosn of a program which contain a compelte set of code and can be used over and over again by other programs. In your experience with teh NWN2 scripting editor you have already seen many functions created by the NWN2 folks. These are functions that contain compelx code that you never have to (hopefully) worry about. All you have to do is call (use) that function in aother program. You can create your own functions and add them to the NWN2 library of existing functions. You can then use these custom made functions in other programs, saving you hour of programming time and frustration. This section is an introduction on how to create functions in the NWN2 scripting environment.
Creating a Function The following program illustrates the creation of a custom function:
The above funtion is saved as ta_speak (I begin all of my custom functions with my initials so they ar enot confused with the ones created by the NWN2 folks). The custom function has the following.
Using the Function (Function Calling) The program below uses (calls) the above function.
The above program has the following:
The above program will now cause the word "Hello NWN2!" to float over the Pcs head.
Conclusion Creating your own custom functions is easy. It offers a powerful way of creating your own NWN2 library of code that fits your style of coding and specific applications or your module.
Where do we go from here? THe next section on Functions shows how to make your custom functiosn even more powerful through the passing of parameters. These act like information messages to make your custom functoins preform different tasks.
|
|