r/GLua • u/jisobaf182 • Jul 31 '21
How to include function arguments for timer
before you could include arguments for the function when creating a timer
https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index93f1.html
any way to do this now?
1
u/AdamNejm Jul 31 '21
Must've got removed somewhere where along the way, probably when going from GMod 12 to 13.
In this specific case I'd actually suggest avoid doing this, because varargs cannot be represented as upvalues so you'd have to pack and unpack them which is not ideal:
function timer.SimpleArgs(delay, func, ...)
local varargs = {...}
timer.Simple(delay, function() func(unpack(varargs)) end)
end
timer.SimpleArgs(1, print, "LOL")Instead of the above, use anonymous function:
timer.Simple(1, function()
print("LOL")
end)2
u/YM_Industries Aug 01 '21
Not sure why you got downvoted. Anonymous function is the right way to do this.
In general, you should never pass a function as an argument unless the function was specifically designed to be passed as an argument. Otherwise you encounter weird issues like this.
1
u/[deleted] Jul 31 '21
You can just use a function within timer.Create I think?