2D array issue

Monkey Forums/Monkey Programming/2D array issue

Afrobear(Posted 2014) [#1]
Hey guys! I'm trying to create a 2D array and 'draw' it, It doesn't work as expected. I used a function some guy posted in another topic. My code:

'Import Falling
Import mojo

Const MapWidth=20
Const MapHeight=15

Class FallingGame Extends App
	Field Map:=ArrayCreate(20,15)
	
	Method OnCreate()
		Local I:Int
		Local J:Int
		
		For I=0 To MapWidth-1
			For J=0 To MapHeight-1
				Map[I][J]=1
			End
		End

		SetUpdateRate(30)
	End
	
	Method OnRender()
		Cls()
		
		Local I:Int
		Local J:Int
		
		For I=0 To MapWidth-1
			For J=0 To MapHeight-1
				DrawText(I*16,J*16,Map[I][J])
			End
		End
	End
End

Function Main()
	New FallingGame()
End

'================================

Function ArrayCreate:Int[][](rows:Int, cols:Int)
	Local a:Int[][] = New Int[rows][]
	For Local i:Int = 0 Until rows
		a[i] = New Int[cols]
	End
	Return a
End


What I get: http://prntscr.com/4cr34z

Could somebody help me? Thanks in advance! :)


Afrobear(Posted 2014) [#2]
Nvm, I'm gonna try to simulate a 2D array in an 1D.


Gerry Quinn(Posted 2014) [#3]
I think you reversed your x and y dimensions in DrawText - otherwise it looks okay.

Remember x = column, y = row - easy to get them reversed as they are usually spoken of in opposite orders,