ios cant access variables in array

var arr = new Array()
var i : int=0;
var temp : String;
for(i=0;i<animationSlotsUsed;i++){
temp = arr*;*
}
this for some reason dosent work for me, im using pragma strinct so i can compile on ios. any ideas what is wrong?
oh also i cut out the part populating the array with strings

What errors or warnings, if any, do you get? It helps if we know what is actually happening. Does it just not assign anything to temp? Are you certain animationSlotUsed isn't 0? Then the loop wont run at all.

also remember ; at the end of EVERY code line. Eg. after Array()

perhaps you could declare the array as type of array too? var arr : Array = new Array();

That sounds like it. Otherwise arr is an unknown aka object

1 Answer

1

You are trying to use a dynamic (untyped) array.

There are two types of arrays in Unity: dynamic arrays and builtin arrays.

    http://unity3d.com/support/documentation/ScriptReference/Array.html

I would recommend using a builtin array.

You can convert a dynamic array to a builtin array like this:

/* declare dynamic array */

var dynamicArray = new Array();

/* populate dynamic array with ints */

for ( var i = 0; i < 10; i ++ ) {
    dynamicArray.Push(i);
}

/* convert to builtin array of known type */

var builtinIntArray = dynamicArray.ToBuiltin(int);

Also... unless there is something missing from your code, you never populate the array named arr.

Your code creates a new, empty, untyped array. It never puts any data in the array (unless there is something you're not showing us).