Simple timer for quit

Blitz3D Forums/Blitz3D Beginners Area/Simple timer for quit

MrOnlineCoder(Posted 2015) [#1]
Hi. I am making horror game and I have a question: How I can make timer?
I have a ghost and when player is moving, the ghost is following him. But if player moves backward, ghost isnt moving. So if player is near the ghost when he is moving backward (distnace < 3) then ghost have to appear infront of player and after 1-2 seconds I have to call function gameOver(). What I have in main loop:

If EntityDistance(cam,ghost)<2
MoveEntity ghost,0,0,1      
Delay 1000
End     
EndIf


But with Delay command the world/window dont render, and ghost didnt move forward. So how I can make timer that will run like "in new stream", isnt touching main game/rendering?

Thanks, MrOnlineCoder

P.S sorry for my english, isnt my native


videz(Posted 2015) [#2]
hmm ghost.. following..

another Slender type game I assume?..


Irvau(Posted 2015) [#3]
The thing with Delay() is that it delays ALL program execution. So nothing happens during those 2 secs, and then it resumes.

What I'd do if I were you is to have the main loop run while a global variable is false. Then, once the timer runs down to 0 and the second is over, make that variable true. Thus, the main loop won't happen, and the program ends.

As for the timer itself, you'd have to use a function that uses Millisecs() to compare times. Use one local/global variable to mark the time at which the player triggers the ghost. Then constantly compare the current time with the marked time. Whenever the current time is equal to the marked time + however many milliseconds you want it to wait, then make it execute the necessary code. In this case, simply turn the global variable true.

Hope this helped!


MrOnlineCoder(Posted 2015) [#4]
videz, no.
Irvau, thanks a lot!


_PJ_(Posted 2015) [#5]
CreateTimer
WaitTimer