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:
CODE 2 works :
here are the images

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