Sign in to follow this  
rusztamas

setTimer help!

Recommended Posts

Hello! I don't understand the setTimer wiki, can you please teach me how it works?
I would do this if it would work:

function hello()
local timer = setTimer (60000) -- sets timer to a minute
if timer == 0 then -- checks if timer is 0
outputChatBox ("0") -- outputs, that timer is null
else
return nil
end 
end
addEventHandler ("onClientResourceStart", getRootElement(), hello)

This is a not working script, can you help me to make it work?
Thank you!

  • Like 1

Share this post


Link to post

setTimer expects a callback function which is a function that is called once the timer has expired.

function hello()
  local timer = setTimer(
    function() -- The function that is called when the timer expires
      outputChatBox ("0") -- outputs, that timer is null
    end,
    6000, -- expire after 6000ms
    1 -- execute only 1 time
   )
end
addEventHandler ("onClientResourceStart", getRootElement(), hello)

This example uses an anonymous function. You can however use a named function as well (i.e. just pass for example 'hello' instead of function() ... end)

  • Like 3

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.