How to acces an array inside an array ?

I could acces it but is there a fastet/better way to do it ? (In js)

var a = new Array();

a = GameMaster.Couldbehit[0];
var b:boolean = a[4];
Debug.Log(b);

So i have an array that contains some other arrays.

and i want to acces one member of the array inside the array.

Something like this but it don’t works : GameMaster.Couldbeit[0].Couldbehitar[4]

your array is not inside of an array

One of the big problems with Javascript (and it's bastard brother, UnityScript), is that it allows you to actually do stuff like adding some bools and some arrays to another array. There is no situation where you actually want to do that, because as you've noticed, you've just created a huge headache for yourself. The way to access a nested array is to just index it. From your example, if you want to get the true value from Couldbehitar through Couldbehit, that would be Couldbehit[0][4].

Yep it's true !! I'm thinking of an array that infinitly contains an array now !) ... I try Couldbehit[0][4]. but the debuger said type object does not support slicing... I thing i'm gonna do couldbehitpoison , couldbehitfire ... instead of of making an array that contains an array for every type of hit...

Just out of curiosity... what is it you are actually trying to do here?

It's my strange hit or communication system.. Every Object that have a collider attached, declare itself in a array inside the GameMaster. Then change it's name for the entry number in this array.. When something collide with the object, it use the name of this object and could acces or edit those variables.. So if a projectile hit a characters it will first see if CouldbehitbyProjectile[x] is True ,then Equip[x] = y ,then Life[x] -= 10 ...

1 Answer

1

It is !! Here’s the code that make the array inside an array:

static var Couldbehit = new Array();
static var Couldbehitar = new Array();

Couldbehitar.Add(false);
Couldbehitar.Add(false);
Couldbehitar.Add(false);
Couldbehitar.Add(false);
Couldbehitar.Add(true);
Couldbehit.Add(Couldbehitar); 

as multiple object add their own array inside the array i could not use simply GameMaster.Couldbehitar but i need something like GameMaster.Couldbehit[y].Couldbehitar