ViRuZGamiing Posted December 30, 2015 Share Posted December 30, 2015 Greetings, I'm trying to work with timers and I have some questions about which is the best way to complete this idea. I have a timer that runs for 15 seconds and need to do something when that timer runs out, Should I give my timer a name and create another timer which kills timer 1 after 15 seconds and do what has to be done? If code is needed, I shall provide. Regards Billy Link to comment
Revolt Posted December 30, 2015 Share Posted December 30, 2015 function afterTimerTicks() -- this is triggered after 15 seconds end setTimer(afterTimerTicks, 15000, 1) Link to comment
ViRuZGamiing Posted December 30, 2015 Author Share Posted December 30, 2015 function afterTimerTicks() -- this is triggered after 15 seconds end setTimer(afterTimerTicks, 15000, 1) So what I said is indeed the best way of doing this? My code in the spoiler (It is working fine just wondering if it's the best way of killing a timer after a time function startPeeing () sec = 15 minWidth = 0 count = 15 width = 790 increment = width / sec addEventHandler("onClientRender", root, peeBarRender) local peeTimer = setTimer( function () width = width - increment count = count - 1 end, 1000, sec) setTimer ( function() killTimer(peeTimer) removeEventHandler("onClientRender", root, peeBarRender) end, 15000, 1) end Regards Billy Link to comment
Addlibs Posted December 30, 2015 Share Posted December 30, 2015 (edited) You do not need to kill the timer. Once the timer finishes executing code it kills itself, that is, unless it is indefinite. Edited December 30, 2015 by Guest Link to comment
Army@1 Posted December 30, 2015 Share Posted December 30, 2015 killTimer can be use in the following ways. local x = 1 function aTimer() x = x+1 end -- this is an infinite timer which runs every 10 seconds. myTimer = setTimer(aTimer, 10*1000, 0) -- kill the timer when x is 10 if x = 10 then killTimer(myTimer) end -- or kill the timer after 1 minute (after myTimer has ran 6 times). setTimer(killTimer, 60*1000, 1, myTimer) -- Link to comment
ViRuZGamiing Posted December 30, 2015 Author Share Posted December 30, 2015 Okay and suppose the player leaves during a timer, I guess I'd have to kill it then as well? Regards Billy Link to comment
Revolt Posted December 30, 2015 Share Posted December 30, 2015 Okay and suppose the player leaves during a timer, I guess I'd have to kill it then as well?Regards Billy Only if it is executed by the server. Link to comment
Army@1 Posted December 31, 2015 Share Posted December 31, 2015 Okay and suppose the player leaves during a timer, I guess I'd have to kill it then as well?Regards Billy Only if it is executed by the server. I am wondering, what would happen to a timer if it was executed by the client? Link to comment
Revolt Posted December 31, 2015 Share Posted December 31, 2015 Army@1, it would terminate itself since the player has actually left the server. Link to comment
Army@1 Posted December 31, 2015 Share Posted December 31, 2015 (edited) Army@1, it would terminate itself since the player has actually left the server. I see. It would probably output an error but there would be no client to receive it, right? Edited December 31, 2015 by Guest Link to comment
Revolt Posted December 31, 2015 Share Posted December 31, 2015 It is not related in any way with the server. setTimer(..) on a client will set the timer locally, and when player leaves, all Lua execution terminates. It is different from the server Lua scripts since they run all the time (whenever the server is running, so server variable/process cleanup is recommended to lower RAM/processor usage) Link to comment
Army@1 Posted December 31, 2015 Share Posted December 31, 2015 It is not related in any way with the server. setTimer(..) on a client will set the timer locally, and when player leaves, all Lua execution terminates. It is different from the server Lua scripts since they run all the time (whenever the server is running, so server variable/process cleanup is recommended to lower RAM/processor usage) Didn't know that. Thanks. 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