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

Concatenation

Concatenation means add to the end or append. You will find that there are times when the ability to connect one string to another is very helpful. This section gives a brief but important example of how this is done.


Connecting Two Strings

The following program is an example of concatenating (connecting together) two strings:


void main( )
{
  object oPC = GetEnteringObject();
  string txtStringl = "This string has ";
  string txtString2 = "another string connected to it.";
 string txtBigString;
  txtBigString = txtStringl + txtString2 + "Thanks!";
  FloafngTextStringOnCreature(txtBigString, oPC);
}


An analysis of the above program yields:
•    Two string variables where declared each with a different string assinged to them
      (txtStringI and txtString2).
•    A third string variable (txtBigString) was declared without an assignment.
•    Three strings were concatenated together and assigned to the variable txtBigString.
•    The + symbol is used to concatenate two or more strings.
•    You can concatenate assigned string variables or a string (as with the last string: "Thanks!").

When you try the above program in the NWN2 game using the previously completed Program I module, you will see the string:

This string has another string connected to it. Thanks!


...Over the top of your PC for every move over the triggered area.


An Application

An interesting application of concatenation is shown in the program below:


void main( )
{
 object oPC = GetEnteringObject(); Jut Number;
 string txtNumber; string Message;
 Number = d6(2);
   txtNumber = IntToString(Number);
   Message = "The number I got is " + txtNumber; FloatingTextStringOnCreature(Message, oPC);
}


If the above program is compiled in the NWN2 editor with the previously created Program I module, the NWN2 game using that same module will dispay:

The number I got is XX


Where XX is the value of the random number the program received from the simulated six-sided dice.


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.