Banging my head against the array wall...

Monkey Forums/Monkey Programming/Banging my head against the array wall...

Chroma(Posted 2011) [#1]
Why doesn't this work?? Btw, map is a Field of map:Int[][] and w=3 and h=3.

		Self.map = [ New Int[w], New Int[h] ]
		For Local b:Int = 0 To h - 1
			For Local a:Int = 0 To w - 1
				Self.map[a][b] = 1
			Next
		Next



Chroma(Posted 2011) [#2]
It works if I put in an actual number but not a variable representing an Int? Why is that? Is this for real?? Are we not able to do something so simple as iterate through a multi-dimensional array with a nested For/Next loop?!

Edit: If anyone could put in their two cents I'd appreciate it. I've already lost about a day on this... Thanks.


muddy_shoes(Posted 2011) [#3]
http://monkeycoder.co.nz/Community/posts.php?topic=822


Chroma(Posted 2011) [#4]
What?!!? That's clear as muddy_shoes...


muddy_shoes(Posted 2011) [#5]
Okay. What do you think this line is doing?

Self.map = [ New Int[w], New Int[h] ]


Your code suggests that you believe that is declaring an array with w rows with h columns. It isn't. It is declaring an array with 2 rows, one with w columns and one with h columns. The thread linked contains a fairly detailed post explaining this and also a post with a helper function to declare two-dimensional arrays.

I don't know what your issues are with using variables rather than literal values in your declaration as you haven't provided the full code example or any description of what "not working" or "working" means. The issue I see with the code as posted is that it will go out of bounds of the array and a literal value or a variable containing the same value should make no difference.


hardcoal(Posted 2011) [#6]
what exactly is a map for?
I didnt get into this map and the tutorial doesnt really explains...


Chroma(Posted 2011) [#7]
I'm posting code from another thread dealing with this same topic. But in all honesty, what I think that line is doing is irrelevant. Why? Because, all this should be in the docs and I shouldn't even be here having to ask how to make a two dimensional array.

You're code jargon isn't getting your point across by any means. What I'm trying to do is the equivalent of Array[3,3] in BlitzMax. If you know the straight, to the point, direct answer...I'd appreciate it. But please don't try and lead me to some time-consuming quest for a eureka moment when none of this is in the docs.

Thanks.


Chroma(Posted 2011) [#8]
I didnt get into this map and the tutorial doesnt really explains...

There is a severe lack of examples in the docs, which makes coming here to get answers and "trying to be led down the path of enlightenment" by some people here, very frustrating.

Maps are a sort of list where you have a key and a value. The key is usually a string and the value can be pretty much anything (image, sound, or your own custom Class). Then you just insert an object into the map using a key for access. Then get the object back when needed by calling the key.


muddy_shoes(Posted 2011) [#9]
I can appreciate that you're feeling frustrated but I don't see why I'm a target here. I didn't write the docs. What I have done is written a number of posts explaining how this works for several people and posted code that actually does the task you're trying to do, here: http://monkeycoder.co.nz/Community/post.php?topic=822&post=6651.

If there's something you're not understanding then you are going to have to be clearer what that is. I apologise if you find what I've written to be "code jargon", but we are after all talking about code. Which terms are you not familiar with? Array? Row? Column?


therevills(Posted 2011) [#10]
What I'm trying to do is the equivalent of Array[3,3] in BlitzMax


Simple answer: You cant, Monkey only deals with single dimension arrays. What you are have been doing is arrays of arrays. Muddy has pointed you in the right direction in post #3.