Skip to content

Commit

Permalink
Add timer(snf)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vurv78 committed Nov 13, 2023
1 parent 342f156 commit 1a78d0d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lua/entities/gmod_wire_expression2/core/timer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,25 @@ end

__e2setcost(10)

e2function void timer(string name, number delay, number reps, function callback)
-- Create "anonymous" timer using address of arguments, which should be different for each function call.
-- Definitely hacky, but should work properly. I think this is better than just incrementing a number infinitely.
e2function void timer(number delay, function callback)
local fn, ent = callback:Unwrap("", self), self.entity
addTimer(self, name, delay, reps, function()
addTimer(self,("%p"):format(args), delay, 1, function()
ent:Execute(fn)
end)
end

-- Create "anonymous" timer using address of arguments, which should be different for each function call.
-- Definitely hacky, but should work properly. I think this is better than just incrementing a number infinitely.
e2function void timer(number delay, function callback)
e2function void timer(string name, number delay, function callback)
local fn, ent = callback:Unwrap("", self), self.entity
addTimer(self,("%p"):format(args), delay, 1, function()
addTimer(self, name, delay, 1, function()
ent:Execute(fn)
end)
end

e2function void timer(string name, number delay, number reps, function callback)
local fn, ent = callback:Unwrap("", self), self.entity
addTimer(self, name, delay, reps, function()
ent:Execute(fn)
end)
end
Expand Down

0 comments on commit 1a78d0d

Please sign in to comment.