A General Question

I’m just trying to understand something:

var shoes = new Array();

This sets up a variable called shoes that is a array. Yes?

var shoes : GameObject[ ];

This sets up a variable shoes that is a GameObject - but what do the brackets mean? Is it an array of GameObjects? An array of shoes?

Thanks for any help in understanding this.

Mitch

Actually, I have a question about arrays too …

var directions = new array(6)

Without the “;” sets up an array in JS, then can you populate it two ways … ?

var directions = new array("up","down","left","right","top","bottom");

or

var directions = new array(6)
directions[0] = "up";
directions[1] = "down";
directions[2] = "left";
directions[3] = "right";
directions[4] = "top";
directions[5] = "bottom";

Either way, directions[2] = left, correct?

Davey… Correct… Assuming you use Array instead of array :slight_smile:

You can also use:

var ar = new Array();

ar.Add(“Up”);
ar.Add(“Left”);
etc…

you can also use the Pop, Shift and a whole heap of cool array methods… using things like FIFO, LIFO, FILO etc…

Mitch, yes

var shoes : GameObject[ ];

will give you an array of GameObjects whose var name is shoes… :slight_smile:

So you can reference them as shoes[1], shoes[0] etc…

shoes[2].tranform.position.x = 10;

Seon.

When you use the following syntax you get a .NET native builtin array:

var Foo : GameObject[ ];

While it is an array it’s quite a bit different than normal JS arrays:

var Blah : Array;

Builtin arrays can be much faster in iteration loops, they require all entries to be of the same data type (JS arrays allow mixing of data types within its entries) and they cannot be resized. Also, you can use and expose builtin arrays in the Inpsector panel as public variables but you cannot with JS arrays.

Array Class in the docs

Edit: and note that you can in fact convert between the two array types as well! :slight_smile: Very handy stuff to know when you want to maximize performance.

Thank you for that clarification.