Add and use named timers instead
Prevents multiple calls to function when it expires, some functions should only be run once
This commit is contained in:
parent
5694ab896f
commit
1bf4859501
21
script.lua
21
script.lua
@ -42,7 +42,7 @@ function changeExpression(_damage, _expression, ticks)
|
|||||||
end
|
end
|
||||||
|
|
||||||
HEAD.setUV(getExprUV(damage,expression))
|
HEAD.setUV(getExprUV(damage,expression))
|
||||||
wait(ticks, resetExpression())
|
namedWait(ticks, resetExpression, "resetExpression")
|
||||||
end
|
end
|
||||||
function setExpression(damage, expression)
|
function setExpression(damage, expression)
|
||||||
face_damage=damage
|
face_damage=damage
|
||||||
@ -111,6 +111,25 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- named timers (this one is mine but heavily based on the other) --
|
||||||
|
-- if timer is armed twice before expiring it will only be called once) --
|
||||||
|
do
|
||||||
|
local timers = {}
|
||||||
|
function namedWait(ticks, next, name)
|
||||||
|
-- main difference, this will overwrite an existing timer with
|
||||||
|
-- the same name
|
||||||
|
timers[name]={t=world.getTime()+ticks,n=next}
|
||||||
|
end
|
||||||
|
function tick()
|
||||||
|
for key, timer in pairs(timers) do
|
||||||
|
if world.getTime() >= timer.t then
|
||||||
|
timer.n()
|
||||||
|
timers[key]=nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Tick function --
|
-- Tick function --
|
||||||
function tick()
|
function tick()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user