From 37b64ff616df3475e228d6beb3727de2afd2b6c2 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 27 Mar 2012 00:37:31 +0300 Subject: Add minetest.after(time, func) --- builtin/builtin.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'builtin') diff --git a/builtin/builtin.lua b/builtin/builtin.lua index 9b2bed33f..4c74b1c5f 100644 --- a/builtin/builtin.lua +++ b/builtin/builtin.lua @@ -795,6 +795,30 @@ minetest.registered_on_newplayers, minetest.register_on_newplayer = make_registr minetest.registered_on_dieplayers, minetest.register_on_dieplayer = make_registration() 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 -- -- cgit v1.2.3