Timeframe questions
BlitzMax Forums/BlitzMax Beginners Area/Timeframe questions
| ||
Hi, I am writing a demo (scene.org) which has multiple parts but I'm having problems with the loop: It should go something like this : While not ESC do function 1 for 30 seconds do function 2 for 10 seconds do function 3 for 45 seconds END WHILE How can I allow a function to perform for only X seconds ? Thanks in advance. |
| ||
This might help...Function tens(timerval:Int) While timerval+10000 > MilliSecs() Cls DrawText "This is 10 second function",0,0 DrawText ((timerval+10000)-MilliSecs())/1000,0,10 Flip Wend End Function Function fifteens(timerval) While timerval+15000 > MilliSecs() Cls DrawText "This is 15 second function",0,0 DrawText ((timerval+15000)-MilliSecs())/1000,0,10 Flip Wend End Function Graphics 800,600 tens(MilliSecs()) fifteens(MilliSecs()) |
| ||
Here is a more complicated one:Type TFunctionHandler Field Time:Int = MilliSecs() Field Elapsed:Int Field Functions:TFunction[] = New TFunction[0] Field Current:Int = 0 Function create:TFunctionHandler() Local FH:TFunctionHandler = New TFunctionHandler Return FH End Function Method AddFunction(Func_(),Time:Int) Functions = Functions[..Functions.length+1] Local F:TFunction = New TFunction F.Func = Func_ F.Time = Time Functions[Functions.length-1] = F End Method Method Update() If Elapsed - Time > Functions[Current].Time Then Current:+1 Time = MilliSecs() If Current > Functions.Length-1 Then Current = 0 EndIf EndIf Functions[Current].Func() Elapsed = MilliSecs() End Method End Type Type TFunction Field Func() Field Time:Int End Type Graphics 800,600,0 Global Handler:TFunctionHandler = New TFunctionHandler Handler.AddFunction(Draw1,3000) Handler.AddFunction(Draw2,4000) Handler.AddFunction(Draw3,2000) While Not KeyHit(Key_Escape) Cls Handler.Update() DrawText "Time : " + (Handler.Elapsed - Handler.Time),20,20 Flip Wend Function Draw1() DrawText "First Massage stays for 3 sec.",200,200 End Function Function Draw2() DrawText "Second Massage stays for 4 sec.",200,200 End Function Function Draw3() DrawText "Third Massage stays for 2 sec.",200,200 End Function |
| ||
I'm trying to do something similar at the moment whereby when certain other tasks are done, with any time that is remaining for a given frame I wasn to do other tasks. Problem is you have to keep checking Millisecs() a lot so that you don't overrun how much time is left. It'd be nice if there were timers that would actually trigger of functions automatically/pre-emptively. |
| ||
Wow thanks I was just looking for this. I want to make damage at double strength for 30 seconds and other interesting things. Thanks guys!! :) |