- Home /
Deriving length of a given dimension in a 2D array
'map' in this case is a 2D array of strings, all containing '#' (effectively a blank map to be used in procedural generaion, say, in a roguelike).
function convertMapToGui (map:String[,]) {
var mapGuiString: String;
Debug.Log(map.Length);
for (var x = 0; x < map.Length; x++) {
for (var y = 0; y < 6; y++) { //Figure out how to get both dims later. '6' ain't gonna cut it. :p
mapGuiString += (map[x,y].ToString);
}
mapGuiString += ('\n');
}
return mapGuiString;
}
What I'm trying for here is a function that will turn that array into a single string I can display by sticking in a GUI box, wich each row being a line of it.
The array is 10x40 and map.Length returns '400', telling me its combining both dimensions and returning that.
Question is, how do I get the length for each dimension on its own?
(Yes, I know there's WAY more wrong here, but I'm posting one question at a time.)
Answer by Benproductions1 · Jul 22, 2013 at 11:27 PM
http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F
From a single google search :P
As opposed to my 10 or 20. $$anonymous$$ust've been looking up the wrong things or something. Useful info all that, found the answer at the very bottom of the page. Thanks!
I just looked up "Unity Built-in array", trying to find the documentation on how built-in arrays work ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613110640im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to create in array variable in JS/unityscript? 1 Answer
array out of range while updating mesh variables 4 Answers
Determining groups in a 2D array by checking neighbours (and their neighbours etc) 2 Answers
array.length read only? workaround? 2 Answers
check occurence of int in 2darray c# 3 Answers