SetLocalArrayInt

From NWN Lexicon



Contents

[edit] SetLocalArrayInt(object, string, int, int)

Simulates storing a local integer in an array.

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

[edit] Parameters

oidObject

Object to store array on.

sVarName

Name of array.

nVarNum

Position (index) within array to store variable in.

nValue

The value to store in the array.


[edit] 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 integer object on whatever object you passed in through the parameters. This local int is called sVarName + nVarNum, so in otherwords if the following is executed:

SetLocalArrayInt(oPC, "myarray", 1, 10);

What actually happens is:
SetLocalInt(oPC, "myarray1", 10);



[edit] Remarks

Found in nw_o0_itemmaker.nss on line 22.

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.


[edit] Known Bugs

None.


[edit] Requirements

#include " nw_o0_itemmaker "

[edit] Version

1.28

[edit] Example

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

[edit] See Also

functions: 

SetLocalInt



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

Personal tools
Categories