map editor help.

BlitzMax Forums/BlitzMax Beginners Area/map editor help.

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

heres my current code. Please look at the createtile function and tell me what I'm doing wrong.

Ill post the first code which doesnt work because of an index out of bounds in an array and the other code which works but wothout the createtile function.

CODE 1:
Strict

Rem 
MapEditor Version 0.1
Author   : Amon
Compiler : BlitzMax
EndRem

Incbin "backblock.png"
Incbin "icon.png"

Graphics 800,600,16,0

SetMaskColor 0,0,0

Global tiles:TImage = LoadAnimImage("incbin::backblock.png",50,50,0,9,MASKEDIMAGE)
Global icon:TImage = LoadImage("incbin::icon.png",MASKEDIMAGE)

Global tileframe:Int = 0

Global mapx:Int = 16
Global mapy:Int = 12
Global x:Int
Global y:Int
Global image:String

Global map:Int[mapx,mapy]

Type tile

	Field x:Int, y:Int
	Field image
	
End Type

Repeat 

	Cls
	
		drawtile()
		drawcurser()
		
		changetile()
		
		If MouseDown(KEY_MOUSELEFT) Then createtile()
	Flip
	
Until KeyHit(KEY_ESCAPE)

Function drawtile()

	Local xpos:Int = 0
	Local ypos:Int = 550
	Local frame:Int = 0
	
	For Local i:Int = 0 To 8
	
		DrawImage tiles,xpos,ypos,frame
		
		xpos:+50
		
		frame:+1
		
		If frame > 8 Then frame = 0
		
	Next
	
End Function

Function drawcurser()
	
	Local x:Int = MouseX()/50
	Local y:Int = MouseY()/50
	
	DrawImage icon,x*50,y*50,0

	
End Function

Function createtile()

	Local t:tile = New tile
	t.x = MouseX()
	t.y = MouseY()
	t.image = tiles
	
	map[mapx,mapy] = tileframe
	
End Function
		
Function changetile()

	If MouseHit(KEY_MOUSERIGHT) 
	
		tileframe:+1
		
		If tileframe > 8 Then tileframe = 0
		
	End If
	
End Function


CODE 2 works :

Global tiles:TImage = LoadAnimImage("incbin::backblock.png",50,50,0,9,MASKEDIMAGE)
Global icon:TImage = LoadImage("incbin::icon.png",MASKEDIMAGE)

Global tileframe:Int = 0

Global mapx:Int = 16
Global mapy:Int = 12
Global x:Int
Global y:Int
Global image:String

Global map:Int[mapx,mapy]

Type tile

	Field x:Int, y:Int
	Field image
	
End Type

Repeat 

	Cls
	
		drawtile()
		drawcurser()
		changetile()
		
	Flip
	
Until KeyHit(KEY_ESCAPE)

Function drawtile()

	Local xpos:Int = 0
	Local ypos:Int = 550
	Local frame:Int = 0
	
	For Local i:Int = 0 To 8
	
		DrawImage tiles,xpos,ypos,frame
		
		xpos:+50
		
		frame:+1
		
		If frame > 8 Then frame = 0
		
	Next
	
End Function

Function drawcurser()
	
	Local x:Int = MouseX()/50
	Local y:Int = MouseY()/50
	
	DrawImage icon,x*50,y*50,0

	
End Function
		
Function changetile()

	If MouseHit(KEY_MOUSERIGHT) 
	
		tileframe:+1
		
		If tileframe > 8 Then tileframe = 0
		
	End If
	
End Function



here are the images