Fix and extend minetest.after(time, func, param)
authorPerttu Ahola <celeron55@gmail.com>
Tue, 27 Mar 2012 05:17:42 +0000 (08:17 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 27 Mar 2012 05:17:42 +0000 (08:17 +0300)
builtin/builtin.lua
doc/lua_api.txt

index 4c74b1c5f426c2bf911d19c10b93511bb749c6b4..c09697045b60fd07324f0495f11361302047297c 100644 (file)
@@ -802,21 +802,21 @@ minetest.registered_on_respawnplayers, minetest.register_on_respawnplayer = make
 minetest.timers_to_add = {}
 minetest.timers = {}
 minetest.register_globalstep(function(dtime)
-  for indes, timer in ipairs(minetest.timers_to_add) do
-    table.insert(minetest.timers, timer)
-  end
-  minetest.timers_to_add = {}
-  for index, timer in ipairs(minetest.timers) do
-    timer.time = timer.time - dtime
-    if timer.time <= 0 then
-      timer.func()
-      minetest.timers[index] = nil
-    end
-  end
+       for _, timer in ipairs(minetest.timers_to_add) do
+               table.insert(minetest.timers, timer)
+       end
+       minetest.timers_to_add = {}
+       for index, timer in ipairs(minetest.timers) do
+               timer.time = timer.time - dtime
+               if timer.time <= 0 then
+                       timer.func(timer.param)
+                       table.remove(minetest.timers,index)
+               end
+       end
 end)
 
-function minetest.after(time, func)
-  table.insert(minetest.timers_to_add, {time=time, func=func})
+function minetest.after(time, func, param)
+               table.insert(minetest.timers_to_add, {time=time, func=func, param=param})
 end
 
 --
index bfde0a8705957765b40923441f7fc61ea4aea296..3a5927e9cc0525c4b7c7d679de10872f7c5d659c 100644 (file)
@@ -467,8 +467,9 @@ minetest.sound_play(spec, parameters) -> handle
 ^ parameters = sound parameter table
 minetest.sound_stop(handle)
 
-minetest.after(time, func)
+minetest.after(time, func, param)
 ^ Call function after time seconds
+^ param is optional; to pass multiple parameters, pass a table.
 
 Global objects:
 minetest.env - environment reference