An array error message?

BlitzMax Forums/BlitzMax Beginners Area/An array error message?

Amon_old(Posted 2004) [#1]
My game currently compiles with no errors and loads up. The problem I'm having now is that when I go to execute a function which has the beginnings of a mapeditor in it, it quits to the Protean IDE with the following message.

Unhandled Exception: Attempt to index array element beyond array lengthfactory [d:\coding folder\blitzmax\mrrobot/main.bmx;155;5]
main [d:\coding folder\blitzmax\mrrobot/main.bmx;74;6]


I think I understand what it means but when I look at my code there is no place where I go outside the limits of the array. I'm still getting to grips with the slight syntax change of BlitzMax so any help would be appreciated.

Offending code below

Function factory()
	Local x:Int,y:Int
	Local mapX:Int,mapY:Int
	Local map[36,22]
	mapX = 40
	mapY = 40
		For x = 0 To 36
			For y = 0 To 22
				map[x,y] = 1
			Next
		Next
		
		Repeat
				
				
				For x = 1 To 36
					For y = 1 To 22
						
						DrawImage icon,MouseX(),MouseY(),0
						If map[x,y] = 1
'							DrawImage blank,map[x,y],map[x,y],0	
							DrawImage rplat,mapX+map[x,y],mapY+map[x,y],1
						EndIf
					Next
				Next
		
		Until KeyHit(KEY_ESCAPE)

End Function



Murilo(Posted 2004) [#2]
Local map[36,22]
will create elements 0-35 (36 elements) and 0-21 (22 elements), so your "For...Next" loops are falling outside of the array bounds. Arrays are zero based.

Hope this helps.


Amon_old(Posted 2004) [#3]
oops. ;)

Thx. Dyslexia for cure found soon :D