aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-03-27 00:37:31 +0300
committerPerttu Ahola <celeron55@gmail.com>2012-03-27 00:37:31 +0300
commit37b64ff616df3475e228d6beb3727de2afd2b6c2 (patch)
treedcdb6f5b14213dd5dfdb015c51046a0837e53c57 /builtin
parenta2fd8d1db10bc5b018d40d9b9ffd8595c7543112 (diff)
downloadminetest-37b64ff616df3475e228d6beb3727de2afd2b6c2.tar.gz
minetest-37b64ff616df3475e228d6beb3727de2afd2b6c2.tar.bz2
minetest-37b64ff616df3475e228d6beb3727de2afd2b6c2.zip
Add minetest.after(time, func)
Diffstat (limited to 'builtin')
-rw-r--r--builtin/builtin.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/builtin/builtin.lua b/builtin/builtin.lua
index 9b2bed33f..4c74b1c5f 100644
--- a/builtin/builtin.lua
+++ b/builtin/builtin.lua
@@ -796,6 +796,30 @@ minetest.registered_on_dieplayers, minetest.register_on_dieplayer = make_registr
minetest.registered_on_respawnplayers, minetest.register_on_respawnplayer = make_registration()
--
+-- Misc. API functions
+--
+
+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
+end)
+
+function minetest.after(time, func)
+ table.insert(minetest.timers_to_add, {time=time, func=func})
+end
+
+--
-- Set random seed
--