Jump to content

setTimer variable scope bug


JeViCo

Recommended Posts

I've recently tried to do something like this

function drawSlot()

end
addEventHandler("onClientRender", root, drawSlot)
setTimer(removeEventHandler, 3000, 1, "onClientRender", root, drawSlot)

however i keep getting warning: 'removeEventHandler' expected function at argument 3 got nil
everything works fine by the code below:

setTimer(function()
	removeEventHandler("onClientRender", root, drawSlot)
end, 3000, 1)

Is that mta bug?
btw _G["drawSlot"] gives same warning

Edited by JeViCo
Link to comment
  • Moderators
13 hours ago, JeViCo said:

Is that mta bug?

It is a limit. Timer are an async method. It requires a lot more work to keep temporary variables alive. So timers will make copies of the values rather managing the original values.

- You can't pass functions in to a timer as argument. (They can't be copied)

- You can pass tables in to a timer as argument, but they will become a (deep) copy.

Edited by IIYAMA
  • Thanks 1
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...