weird loopy jamming my app

BlitzPlus Forums/BlitzPlus Beginners Area/weird loopy jamming my app

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.

You need to master something else first: uniformity. Every app you show here looks different in codestyle. You need to start simple and small, forget about games and other big stuff for a while. You can't learn a language properly if you put your focus on big stuff, and tomorrow you'll be looking at a mess if you don't add a bit of structure.

You could for example adopt this framework:
window=CreateWindow("bla",0,0,640,480)

;
;
; create more stuff here..
;
;

Repeat
	Delay 2
	WaitEvent()
	If EventID()=$803 quit=True
	
	;
	;
	; event-checks of the rest of the app
	;
	;
	
Until quit

;
; clean-up things like images, banks etc. *HERE*
;

SetBuffer DesktopBuffer()
End


Using that framework, here's how things can work:

window=CreateWindow("bla",0,0,640,480)

Global img=CreateImage(160,160)
SetBuffer ImageBuffer(img)
Text 0,0,"Structure!"
Text 0,32,"..please.."

Global canvas=CreateCanvas(0,0,640,480,window)

Repeat
	Delay 2
	WaitEvent()
	If EventID()=$803 quit=True

	evFunction()
	
Until quit

FreeImage img
SetBuffer DesktopBuffer()
End

Function evFunction()
	If EventSource()=canvas
		If EventID()=$203
			x=EventX()
			y=EventY()
			SetBuffer CanvasBuffer(canvas)
				Color x Mod 256,y Mod 256,128
				TileBlock img,x/4,y/4
				Rect 320-x,240-y,240,200,True
				TileImage img,x/2,y/2
				Color y Mod 256,x Mod 256,128
				Rect 320-x*2,240-y*2,120,100,True
				TileImage img,x,y
			FlipCanvas canvas
		EndIf
	EndIf
End Function


So, put all the eventchecking in functions .. they're sorted then, and shielded from everything else.