Thank you in advance

Code: Select all
Repeat
If MouseClicked
StartTime = ElapsedMilliseconds() ; record start time
EndIf
If StartTime > 0 ; if there is an active countdown
If ElapsedMilliseconds - StartTime > 3 * 1000 ; wait 3 seconds (3000 ms)
PlaySound(Alert)
StartTime = 0 ; disable timer again
EndIf
EndIf
Forever
Yes, that is because 'MouseClicked' never gets #True and because '(' and ')' are missing after the 2nd 'ElapsedMilliseconds'.J@ckWhiteIII wrote:@kenmo: I never hear a sound :/
...I added an own sound, of course...
Code: Select all
OpenWindow (0, 0, 0, 400, 300, "Timer", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
If EventGadget() = 0 And EventType() = #PB_EventType_LeftClick
StartTime = ElapsedMilliseconds()
EndIf
EndSelect
StartDrawing(CanvasOutput(0))
If StartTime
Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF)
DrawText(5, 10, Str(ElapsedMilliseconds() - StartTime) + " ms", $000000, $FFFFFF)
DrawText(5, 30, Str((ElapsedMilliseconds() - StartTime) / 1000) + " Seconds", $000000, $FFFFFF)
If ElapsedMilliseconds() - StartTime > 3 * 1000 ; wait 3 seconds (3000 ms)
StartTime = 0 ; disable timer again
Circle(200, 50, 28, Random($FAFAFA))
EndIf
EndIf
StopDrawing()
Delay(10)
ForEver
Code: Select all
Procedure CountDown ()
If StartTime > 0 ; if there is an active countdown
If ElapsedMilliseconds () - StartTime > 3 * 1000 ; wait 3 seconds (3000 ms)
PlaySound(1)
StartTime = 0 ; disable timer again
EndIf
EndIf
EndProcedure
If circlex < 0
StartTime = ElapsedMilliseconds() ; record start time
PlaySound (0)
circlex = 320
circley = Random (480)
pseudomovex = movex
pseudomovey = movey
movex = 0
movey = 0
Score2 + 1
CountDown ()
movex = pseudomovex
movey = pseudomovey
EndIf
Why not make the CountDown a thread ?J@ckWhiteIII wrote:That works much better
This is how I'm using it:Code: Select all
Procedure CountDown () If StartTime > 0 ; if there is an active countdown If ElapsedMilliseconds () - StartTime > 3 * 1000 ; wait 3 seconds (3000 ms) PlaySound(1) StartTime = 0 ; disable timer again EndIf EndIf EndProcedure If circlex < 0 StartTime = ElapsedMilliseconds() ; record start time PlaySound (0) circlex = 320 circley = Random (480) pseudomovex = movex pseudomovey = movey movex = 0 movey = 0 Score2 + 1 CountDown () movex = pseudomovex movey = pseudomovey EndIf
Because you get unnecessary overhead.Nubcake wrote: Why not make the CountDown a thread ?
Code: Select all
Procedure CountDown ()
If Blocky ; if there is an active countdown
If ElapsedMilliseconds () - StartTime > 3 * 1000 ; wait 3 seconds (3000 ms)
StartTime = 0 ; disable timer again
PlaySound(0)
movex = pseudomovex
movey = pseudomovey
EndIf
EndIf
EndProcedure
If circlex < 0
StartTime = ElapsedMilliseconds() ; record start time
PlaySound (0)
circlex = 320
circley = Random (480)
pseudomovex = movex
pseudomovey = movey
movex = 0
movey = 0
Score2 + 1
CountDown ()
EndIf
Code: Select all
Background.i = #Black
BallY.i = 150
BallDir.i = 1
If InitSprite() And InitMouse()
If OpenWindow(0, 0, 0, 400, 300, "Left-click to set timer, right-click to exit", #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)
Repeat
ExamineMouse()
; Red screen when clicked
If (MouseButton(1))
Background = #Red
StartTime = ElapsedMilliseconds()
EndIf
; Blue screen after timeout
If (StartTime > 0)
If (ElapsedMilliseconds() - StartTime) > 2*1000
Background = #Blue
StartTime = 0
EndIf
EndIf
; Move ball
If (BallDir > 0)
BallY + 1
If BallY > 290
BallDir = -1
EndIf
Else
BallY - 1
If BallY < 10
BallDir = 1
EndIf
EndIf
; This is a cheap trick so the window won't lock up...
While WindowEvent() : Wend
; Draw screen
ClearScreen(Background)
If StartDrawing(ScreenOutput())
Circle(OutputWidth()/2, BallY, 10, #White)
StopDrawing()
EndIf
FlipBuffers()
Delay(16)
Until MouseButton(2)
HideWindow(0, #True)
Delay(250)
EndIf
EndIf
EndIf