Jump to content

About setTimer


ViRuZGamiing

Recommended Posts

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
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

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

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...