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

Seeing Results

One of the best ways to learn a new programmign language is to be able to see the results of your coding.  It is the purpose of programmign to have teh computer do somethign you want. In the NWN2 system, the purpose of coding is to have the game do something you want. In this section you will discover one method of seeing how your pogram affects the NWN2 game.


Getting into the NWN2 Editor

The first thing to do is to get into the NWN2 editor and then do the following steps:

  1. Create a new module and save it as Program1
  2. Create a new scripts and palce the following code into it:
  3. void main()
    {
    object oPC=GetEnteringObject();
    FLoatingTextStringOnCreature("Hello NWN2!", oPC);
    }

     

  4. Be sure to copy the code exactly as shown. Note tha ttwo of the lines end in semicolon ;.
  5. Remember that C++ code is case sensitive so make sure each letter in your new code is exaclty as shown above.
  6. Compile the program (F7)
  7. If there are no errors, this will be automatically be saved as Script1.
  8. Create a new area.
  9. Once the new area is created, place a trigger on it.
    • Go to the Blueprints windows.
    • Select Triggers.
    • From the resulting selections, select Empty for the trigger type.
    • From the resulting seletions, select NewGeneric.
    • Your mouse arrow will change to a crosshairs, click on 4 different points in front of the Start symbol in your new arena. This will create an orange rectangle.
    • Go to the third menu bar at the otp and click on Select Objects.
    • The mouse now changes back to an arrow.
  10. With the mouse, select the orange trigger area you just created, click on it, a green area will appear, then right click and a pop-up menu will appear.
  11. From the pop-up menu select Properties (new window)
  12. In the resulting Properties window under the Scripts area select the on Enter Script.
  13. In the box just to the right of the On Enter Script, type in the name of your new script, which by defualt is Script1.
  14. Go to the File menu and Bake the area.
  15. Save and Exit the NWN2 Editor.
  16. Open the NWN2 game.
  17. Select New Game.
  18. Select New Module.
  19. Select your saved module Program1
  20. Select Select Character
  21. Pick any character you wish
  22. Once the game screen comes up, move your character (PC) over the trigger area you created.
  23. Observe that the text: Hello NWN2! now appears over the PCs head.
  24. Observe that the same text also appears in the message box in the lower left of your screen.
  25. Every time you move your character over that area, the message will appear.

 


 

Making Things Simple

You don have to go through all of the above steps every time you make a new program. You only need to go into the editor, and call up your Program1 module. Now all you need to do is to modifty your Script1 and see the results in the NWN2 game.

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.