Lua "Wait" function

I’m trying to code a function that will do something, then revert it x seconds later (Not that important what it is).
I already know about timer.Simple/Create/Whatever, but that would require a new function, losing the function arguments from the initial function (Which are essential).
Is there any way to implement a lua “wait” function?

Being so vague because it’s a ULX command that probably has some fix already, but I’m really only interested in the question above, not a fix for the code

I’m confused what you mean

This is not essentially true, if you can provide us with more information on exactly what you are trying to do, it’d be easier to help.

timers keep the scope/upvalues that it is created in. Give timer.Simple a shot in your function but make sure to check that the arguments are still valid/defined in the timer.

[lua]
local function test(somestr)
if (somestr) then
somestr = somestr … " suffix"
end

timer.Simple(1, function()
	if (somestr) then
		somestr = "prefix " .. somestr
		print("We have `waited` for 1 second. somestr = \"" .. somestr .. "\"")
	else
		print("somestr is undefined")
	end
end)

end

test(“something”)
[/lua]

Do you mean something like this?



function fnc(a, b, c)
	// do stuff
	timer.Simple(1, function(a, b, c)
		// undo stuff
	end)
end


that would delete the previous arguments (and would then only be accessible via the debug library).



function fnc(a, b, c)
	// do stuff
	timer.Simple(1, function() -- No overriding previous variables.
		print( a, b, c )
		// undo stuff
	end)
end


Oh, wow, ok, thanks