forked from Mirrorlandia_minetest/minetest
Fix and extend minetest.after(time, func, param)
This commit is contained in:
parent
37b64ff616
commit
fa24e6b995
@ -802,21 +802,21 @@ minetest.registered_on_respawnplayers, minetest.register_on_respawnplayer = make
|
|||||||
minetest.timers_to_add = {}
|
minetest.timers_to_add = {}
|
||||||
minetest.timers = {}
|
minetest.timers = {}
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
for indes, timer in ipairs(minetest.timers_to_add) do
|
for _, timer in ipairs(minetest.timers_to_add) do
|
||||||
table.insert(minetest.timers, timer)
|
table.insert(minetest.timers, timer)
|
||||||
end
|
end
|
||||||
minetest.timers_to_add = {}
|
minetest.timers_to_add = {}
|
||||||
for index, timer in ipairs(minetest.timers) do
|
for index, timer in ipairs(minetest.timers) do
|
||||||
timer.time = timer.time - dtime
|
timer.time = timer.time - dtime
|
||||||
if timer.time <= 0 then
|
if timer.time <= 0 then
|
||||||
timer.func()
|
timer.func(timer.param)
|
||||||
minetest.timers[index] = nil
|
table.remove(minetest.timers,index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function minetest.after(time, func)
|
function minetest.after(time, func, param)
|
||||||
table.insert(minetest.timers_to_add, {time=time, func=func})
|
table.insert(minetest.timers_to_add, {time=time, func=func, param=param})
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -467,8 +467,9 @@ minetest.sound_play(spec, parameters) -> handle
|
|||||||
^ parameters = sound parameter table
|
^ parameters = sound parameter table
|
||||||
minetest.sound_stop(handle)
|
minetest.sound_stop(handle)
|
||||||
|
|
||||||
minetest.after(time, func)
|
minetest.after(time, func, param)
|
||||||
^ Call function after time seconds
|
^ Call function after time seconds
|
||||||
|
^ param is optional; to pass multiple parameters, pass a table.
|
||||||
|
|
||||||
Global objects:
|
Global objects:
|
||||||
minetest.env - environment reference
|
minetest.env - environment reference
|
||||||
|
Loading…
Reference in New Issue
Block a user