Android Question Make a sub stop for seconds

IDONTKNOW

New Member
Licensed User
Here is what I have so far. The wait timer works perfectly if you put the message box after the wait for but in the new game sub it immediately says "cool" "yay" without waiting. Any help would be appreciated.

Sub WaitSecs(secs As Int)
Dim WaitTimer As Timer
WaitTimer.Initialize("WaitTimer",0)
WaitTimer.Interval = secs * DateTime.TicksPerSecond
WaitTimer.Enabled = True
Wait For WaitTimer_Tick
WaitTimer.Enabled = False

End Sub

Sub NewGameBtn_Click

WaitSecs(10)
Msgbox("Cool","YAY")

End Sub
 

MarkusR

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Test
    
    Log("Wait")
    Wait For (WaitSecs(10)) Complete (Result As Boolean)
    Log("OK")
    
End Sub

Sub WaitSecs(secs As Int) As ResumableSub

    Sleep(secs*1000)

    Return True

End Sub
 
Upvote 0

udg

Expert
Licensed User
Longtime User
You may find useful my class xToastMessage, an XUI/B4X class born to take the B4A standard ToastMessage to B4J, but which then turned to a more complete tool.
Source code is provided so you can tailor it to your needs.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
you spoke about a game.
a statemaschine will also be useful, a timer will trigger something you do at a current state.
so you can memory the time at state x , next state, condition time1-time2 >= 10 secs then next state
 
Upvote 0
Top