SkrillexX Posted March 11, 2014 Share Posted March 11, 2014 How to check if a Timer i've set earlier is over ( the time is over ) or not , Like for example , i've set a Timer with 5 minutes , how to check if those 5 minutes are over or not Link to comment
Chronos Posted March 11, 2014 Share Posted March 11, 2014 You can use getTimerDetails Link to comment
SkrillexX Posted March 11, 2014 Author Share Posted March 11, 2014 Let's say that i've precised earlier this : setTimer ( randomFunction ,6000000 ,0 ) 600000 = 5 minutes How to check if they're over using getTimerDetails Link to comment
Chronos Posted March 11, 2014 Share Posted March 11, 2014 Check this example from wiki,It might be usefull for you theTimer = setTimer(function() end, 1000, 10) -- A timer that does nothing. function timerDetails() remaining, executesRemaining, totalExecutes = getTimerDetails(theTimer) -- Get the timers details if (remaining and executesRemaining and totalExecutes) then outputChatBox("Time remaining this second: "..remaining.." Executes remaining: "..executesRemaining.." Total executes: "..totalExecutes) else outputChatBox("Timer no longer exists") end end addCommandHandler("timerdetails", timerDetails) Link to comment
SkrillexX Posted March 11, 2014 Author Share Posted March 11, 2014 I've already seen it but it wasn't that useful as i didn't really understand it (I'm a beginner ) Link to comment
DNL291 Posted March 11, 2014 Share Posted March 11, 2014 If you want to know the time left to execute the function, use: local remaining = getTimerDetails(theTimer) But if you want to know if the time stopped running, just use the attached function with setTimer (when it's called, means that the time stopped running). Link to comment
Spajk Posted March 12, 2014 Share Posted March 12, 2014 Could you tell me a bit more on where you are planning to use this, there might be a chance that it could be done without timers using tick count which would improve effectiveness. Link to comment
Moderators Citizen Posted March 12, 2014 Moderators Share Posted March 12, 2014 Let's say that i've precised earlier this : setTimer ( randomFunction ,6000000 ,0 ) 600000 = 5 minutes How to check if they're over using getTimerDetails You need to use a variable to store it like the wiki did. And then use that variable as 1srgument of getTimerDetails. Don't use infinite timer if you want to know if the 5 mins are passed (oh and 5 mins = 5 * 60 secs = 300 * 1000 ms = 300000 ms) in the case of a non infinite timer, getTimerDetails will return false when the timer is done (passed 5 mins). Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now