Jump to content
Sign in to follow this  
Rapax

Multi-dimensional arrays

Recommended Posts

I am embarrassed ask this,but Can someone explain to me why _count = count _multiArray1 select 0; // Output= 4? :confused:

however much i read it I don't understand the Output 4

// Multi-dimensional array example

_multiArray1 = [["Item1",1,2,3],["Item2",4,5,6]];

_count = count _multiArray1; // Output: 2

_count = count _multiArray1 select 0; // Output: 4

thank you

Share this post


Link to post
Share on other sites

Well, "_multiArray1 select 0" is first element of "_multiArray1" array, thus "["Item1",1,2,3]". This first element is also an array, composed of 4 elements. That's why the count command returns 4.

Share this post


Link to post
Share on other sites

Hi, multi-dimensional arrays can be a bit of a bugger when you first work with them.

Try looking at your _multiArray1 like this:

_multiArray1 = [
["Item1",1,2,3], //First entry in the _multiArray1 array (index = 0) which is what you get when you _multiArray select 0;
["Item2",4,5,6] //Second entry in the _multiArray1 array (index = 1) which is what you get when you _multiArray select 1;
];

When you do _multiArray1 select 0;, you get the first entry from your main array: ["Item1",1,2,3]. As you can see, there are four items in that: Item1, 1, 2 and 3. That's why when you do count _multiArray1 select 0;, you get 4 back. It first selects the value from _multiArray1, which is the array with 4 items and then runs the count command on that value.

I hope that explains things for you, what are you trying to do exactly?

Share this post


Link to post
Share on other sites

LOL now I understand it :yay: thank you ProfTournesol

Share this post


Link to post
Share on other sites

BadLuckBurt thank you for your explanation !

to be honest I find myself unable to do nothing, simply it makes me mad dont understand this concepts.

Edited by Rapax

Share this post


Link to post
Share on other sites

You're welcome. After I posted I saw that Prof. Tournesol ninja'd me but I decided to leave it there anyway.

And we've all been there. One thing that always helped me is breaking code down step by step. Sometimes things get a bit too abstract in the beginning when your brain first encounters a new situation and too many things happen at once. But the more you code, the less you need to do that because of the experience you gain :)

Share this post


Link to post
Share on other sites

oh,that is good start, thank you for the link Iceman, It's so glad to ask this way!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×