SetLocalArrayString

From NWN Lexicon
Jump to: navigation, search



SetLocalArrayString(object, string, int, string)

Simulates storing a local string in an array.

void SetLocalArrayString(
    object oidObject,
    string sVarName,
    int nVarNum,
    string nValue
);

Parameters

oidObject

Object to store the array on.

sVarName

Name of the array.

nVarNum

Position (index) in the array to store the variable in.

nValue

String to store in the array.


Description

Although this is hardly an array, it can be accessed like one, and can even be looped through. It works by creating a new local string object on whatever object you passed in through the parameters. This local string is called sVarName + nVarNum, so in otherwords if the following is executed:

SetLocalArrayString(oPC, "myarray", 1, "hello");

What actually happens is:
SetLocalString(oPC, "myarray1", "hello");



Remarks

Found in nw_o0_itemmaker.nss on line 20.

In essence, arrays are nice because they:
a) Allow for cleaner code, and
b) Allows you to make a simple loop statement to get many variables' values, rather than having to type a bunch of variable names yourself.


Known Bugs

None.

Requirements

#include " nw_o0_itemmaker "

Version

1.28

Example

//Sets 10 variables quickly on the PC, using a for loop.
//myarray1 is set to "number 1", 
//myarray2 is set to "number 2", etc.
 
#include "nw_o0_itemmaker"
 
void main()
{
object oPC=GetPCSpeaker();
 
int nLoop;
for (nLoop=1; nLoop<=10; nLoop++)
   {
   SetLocalArrayString(oPC, "myarray", nLoop, "number "+IntToString(nLoop));
   }
}

See Also

functions: 

SetLocalString



 author: Lilac Soul, editor: Charles Feduke, additional contributor(s): Graziano Lenzi