Any sugestions for this setup? (MaxGui)
BlitzMax Forums/BlitzMax Beginners Area/Any sugestions for this setup? (MaxGui)| 
 | ||
| I want to make some kind of "life-emulation", where  generations of "Pixel-beings" can procreate the next. So I want the program to be able to run in the "background", while the user can do something else. I have cut and pasted something of a start, but is this a good way to do something like this? Any suggestions of improvements or alternatives will be greatly apreciated. :) The code so far: 
SuperStrict
Global TankWidth:Int=255,TankHeight:Int=255
Global CanvasWidth:Int=400, CanvasHeight:Int=300
Global ButtonHeight:Int=32, BorderSize:Int=16 
Global EWindow:TGadget=CreateWindow("Evolution", 100,100,CanvasWidth+2*BorderSize,CanvasHeight+ButtonHeight+2*BorderSize)
Global ECanvas:TGadget=CreateCanvas(BorderSize,BorderSize,CanvasWidth,CanvasHeight,EWindow)
Global x:Int=0
Global y:Int=0
Global t:Int,u:Int
ActivateGadget ECanvas
Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_WINDOWCLOSE
     End
  Case EVENT_MOUSEENTER
     HideMouse
 Case EVENT_MOUSELEAVE
     ShowMouse
  Case EVENT_MOUSEMOVE
     x=EventX()
     y=EventY()
  Case EVENT_GADGETPAINT
   End Select
    SetGraphics CanvasGraphics (ECanvas)
    Cls
    For t=0 To Tankwidth-1
		For u=0 To TankHeight-1
			SetColor (Rnd(0,255),Rnd(0,255),Rnd(0,255))
			Plot t,u
		Next
	Next		
	DrawRect  x,y,40,40
    Flip
     RedrawGadget(ECanvas)
Forever
(Of course it also need some buttons and other kind of control.) | 
| 
 | ||
| Get rid of the globals, and especially globals like x, y, t etc. Those are typically used for local loops and such. Make a TLifeemulation type, hide them there, don't put all these things as globals in your app or it'll seriously limit your app after a few hours/days. (depending on your code-speed) Furthermore, not really a bug orso, but be aware that your Redrawgadget(ECanvas) could 've been without the ( ). blah=Bla(a,b,c) Bla a,b,c see the difference? The first one requires ( ) because Bla is a function returning a value. The second one doesn't return anything, so doesn't need ( ). Your code will function with them however.. it's more a matter of style.. | 
| 
 | ||
| @CS_TBL: Thanks; One picks up some habits in ones Programminglife :) I use those globals that "lazy" way when I'm testing stuff and don't want to declare them every time I write a temporary function. pfft :) In the mean time the little program as seen above has progressed some and instead of being random, the pixelbeings are moving around on their own. (there is a lot of them) Now I encounter some strange "hickups". The movement stops and then start again, and I cant figure out why. I have tried to place the drawing stuff under the case EVENT_GADGETPAINT, but thas didn't help. Can it be the way I use RedrawGadget ECanvas? Is it WindowsXP? Is it my PC? Or is it Me? | 
| 
 | ||
| Can't say without seeing it. | 
| 
 | ||
| How are you handling your Canvas redraw? You might prefer to use a Timer, rather than call redraw after the flip, otherwise the frame update will more likely be subject to skipping etc. Have a look at the CreateCanvas example in the docs. It uses a timer which generates an EVENT_TIMERTICK event per "tick" : CreateTimer 60 you could then have this in your select... 
    Case EVENT_TIMERTICK
        RedrawGadget ECanvas
Might make it run a bit smoother? |