Map data only returning 0

BlitzPlus Forums/BlitzPlus Beginners Area/Map data only returning 0

Hi all,
I am attempting to make a wireframe maze game - you know the type, the really early days of games early Ultima and Wizardry type... I (think I) have set everything up (its still in its very early days!) but when I test the maze data, all I seem to return are Zeros. So it doesnt appear to be reading the maze data correctly. This is my 1st crack at getting into data statements, so I still dont fully understand how they work, but with Krylars book and a bit of blood sweat and tears, I'm hoping to crack the nut in the next couple of days. Have a look at the code and see if you can see the (probably really simple) error I have made...

; Wireframe maze drawing program

Graphics 640,480
SetBuffer BackBuffer()

; declare the map variable
Map_Length=16
Map_Height=16
Dim maze(Map_Length,Map_Height)



While Not KeyHit(1)
	; clear the screen
	Cls
	DrawBox
	ReadMaze
	For i=0 To map_Length
		For j=0 To map_height
			Print maze(i,j)
		Next
		Next
	Flip
Wend
End

;******************************
;* Draws a box-like border    *
;* around the main maze       *
;* Player area                *
;******************************
Function DrawBox()
	Line 82,19,294,19
	Line 294,19,294,119
	Line 294,119,82,119
	Line 82,119,82,19
End Function

;******************************
;* Reads the data statements  *
;* to load the maze data      *
;* into the maze()() variable *
;******************************
Function ReadMaze()
	; Read (load) in the maze data into a variable
	Restore MazeData
	For y = 0 To Map_Height-1
		For x = 0 To Map_Length-1
			Read a	; get the map data and store into value
			maze(x,y) = a
		Next ; x
	Next ; y
End Function


.MazeData
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,1,0,1,1,1,0,1,0,1,0,1,1,0,1
Data 1,0,1,0,1,0,0,0,1,1,1,0,1,1,0,1
Data 1,0,1,0,0,0,1,0,0,0,1,0,0,1,0,1
Data 1,0,1,1,1,0,1,0,1,0,1,1,1,1,0,1
Data 1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1
Data 1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1
Data 1,0,1,0,0,0,1,1,0,0,1,0,1,1,0,1
Data 1,0,1,0,1,0,1,1,1,1,1,0,1,1,0,1
Data 1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,1,1,1,0,1,0,1,0,1,1,1,1,0,1
Data 1,0,0,0,1,0,1,0,1,0,0,0,0,1,0,1
Data 1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1


First of all, put the ReadMaze call before the mainloop. No need to read all that data again and again each time..

Next:

in your mainloop you do a nested FOR to print the maze, add '-1' to the forloops, as you did in the ReadMaze function.


Now I'll try to rest/run it in blitz :P :P

also: while DIM'ing, if you need an array of 10 elements, then dim bla(9) will do, so in this case: dim maze(Map_Length-1,Map_Height-1)

another detail:

Read a ; get the map data and store into value
maze(x,y) = a

could ofcourse be:

Read maze(x,y)

..saves the creation/use of 'a' :P

ahyes ^_^

Map_Height and Map_Length aren't globals!

So in the readmaze function the for's go from 0 to -1 :P

Note that a DIM'ed variable is always a global (much to my regrets..)

While we're on it, I'd advice to drop the word map_'Length' here and use map_'Width' instead.. it's a peanuts-remark, I know, but everything is always width/height.. like the Rect command for example..

Another one,

the DrawBox function.. perhaps in the future you come straight from another function that does some drawing.. what if that function changes color? Always add a color r,g,b or color ,,rgb command when you're drawing!

Also, I think you have confused rows and columns.

The value read as maze(x,y) should be maze(y,x).

As a bonus, here's your code, lightly modified by me

And as a bonus I added a mini-mapviewer :P 'ave fun~

; Wireframe maze drawing program

Graphics 640,480,32,2

SetBuffer BackBuffer()

; declare the map variable
Global MapWidth=16
Global MapHeight=16
Dim maze(MapWidth-1,MapHeight-1)  ; sorry ^^; used to this convention without _

ReadMaze()


While Not KeyHit(1)
	; clear the screen
	Cls
	DrawBox()
	DrawMaze()
	Flip
Wend
End

;******************************
;* Draws a box-like border    *
;* around the main maze       *
;* Player area                *
;******************************
Function DrawBox()
	Color 255,255,255
	
	Line 82,19,294,19
	Line 294,19,294,119
	Line 294,119,82,119
	Line 82,119,82,19
End Function

;******************************
;* Reads the data statements  *
;* to load the maze data      *
;* into the maze()() variable *
;******************************
Function ReadMaze()
	; Read (load) in the maze data into a variable
	Restore MazeData
	For y = 0 To MapHeight-1
		For x = 0 To MapWidth-1
			Read maze(x,y); get the map data and store into value
		Next ; x
	Next ; y
End Function

Function DrawMaze()
	Color 255,128,64
	For y=0 To MapHeight-1
		For x=0 To MapWidth-1
			If maze(x,y) ; no '=something' means it's not equal to 0, so "IF bla=1 then" equals "IF bla then" equals "IF bla"
				Plot 30+x*2,20+y*2
			EndIf
		Next
	Next
End Function


.MazeData
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,1,0,1,1,1,0,1,0,1,0,1,1,0,1
Data 1,0,1,0,1,0,0,0,1,1,1,0,1,1,0,1
Data 1,0,1,0,0,0,1,0,0,0,1,0,0,1,0,1
Data 1,0,1,1,1,0,1,0,1,0,1,1,1,1,0,1
Data 1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1
Data 1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1
Data 1,0,1,0,0,0,1,1,0,0,1,0,1,1,0,1
Data 1,0,1,0,1,0,1,1,1,1,1,0,1,1,0,1
Data 1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,1,1,1,0,1,0,1,0,1,1,1,1,0,1
Data 1,0,0,0,1,0,1,0,1,0,0,0,0,1,0,1
Data 1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1


Wow!. That is excellent. Thank's so much for this. I will now go thru the code and see how you did the minimap. Its awesome (well, for my current level of expertise :-) ). I guess I have a bit further to go, but every journey begins with the first step.

Again thanks heaps for the help.