SetLocalArrayInt(object, string, int, int)

Simulates storing a local integer in an array.

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

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.


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);



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.


Known Bugs

Setting a value to a newly created object has some particular nuances. See SetLocalString(object, string, string) for more information.


Requirements

#include "nw_o0_itemmaker"

Version

1.28

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);
     }
}

See Also

functions: GetLocalArrayInt | GetLocalInt | SetLocalInt
categories: Local Variables Functions


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