Problems with "out of data" error

Blitz3D Forums/Blitz3D Beginners Area/Problems with "out of data" error

Benasp(Posted 2006) [#1]
Here is my code:
AppTitle "sample map"
Graphics 640,480,32,2

Const TX = 64
Const TY = 64

tiles = LoadAnimImage("bitmaps\ireland.bmp", TX, TY, 0, 144)

Restore startData

Read maptilewidth
Read maptileheight

While Not KeyDown(1)
	dy = 0 ;dy stands for draw y
	For y = 1 To maptileheight
		dx = 0 ;dx stands for draw x
		For x = 1 To maptilewidth
			Read block
			DrawBlock tiles, dx, dy, block
			dx = dx + TX
		Next
		dy = dy + TY
	Next
;	Flip
Wend
End

.startData
;map data
Data 30, 30

Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
Data 1, 1, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 131, 1, 1
Data 1, 1, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 1, 1
Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1


And my problem is, I can't figure out why I'm getting an "out of data" error for this tilemap, highlighting the:
Read block

line of code. If you don't have an image to use for this code, email me and ask for it. If you can figure it out just by looking, that would be nice.


b32(Posted 2006) [#2]
The Read statement reads all the data until the end. After that, it returns "out of data". To avoid that, reset its pointer using Restore.
In your code, either move this block:
Restore startData

Read maptilewidth
Read maptileheight

into the main loop, or make an extra label after "Data 30, 30" and Restore to there at the beginning of the loop.


Benasp(Posted 2006) [#3]
Thanks a lot, however, I have another question related to this for somebody...how can I scroll this map?


b32(Posted 2006) [#4]
A quick solution might be: offsetting dx.
Use "time = (time + 1)" at the end of the loop and then use "dx = time mod maptilewidth" instead of "dx = 0". Finally, add "-1" after "For y = 0 to maptileheight"
I think the best approach would be using an array:
Dim block(maptilewidth, maptileheight) First, use Read..Data to fill the array with number, then, during the main loop, use the numbers in the array to draw the images.