JeViCo Posted December 15, 2019 Share Posted December 15, 2019 (edited) 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 December 15, 2019 by JeViCo Link to comment
Moderators IIYAMA Posted December 16, 2019 Moderators Share Posted December 16, 2019 (edited) 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 December 16, 2019 by IIYAMA 1 Link to comment
vicisdev Posted December 16, 2019 Share Posted December 16, 2019 6 hours ago, IIYAMA said: - You can pass tables in to a timer as argument, but they will become a (deep) copy. By doing this am I avoiding this deeeeep copy? local myTable = {} -- Some filled in table setTimer(function() callAnotherFunction(myTable) end, 1000, 1) 1 Link to comment
Moderators IIYAMA Posted December 16, 2019 Moderators Share Posted December 16, 2019 4 hours ago, vicisdev said: By doing this am I avoiding this deeeeep copy? local myTable = {} -- Some filled in table setTimer(function() callAnotherFunction(myTable) end, 1000, 1) Correct! 1 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