Add minetest.after(time, func)
authorPerttu Ahola <celeron55@gmail.com>
Mon, 26 Mar 2012 21:37:31 +0000 (00:37 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 26 Mar 2012 21:37:31 +0000 (00:37 +0300)
builtin/builtin.lua
doc/lua_api.txt
games/minimal/mods/experimental/init.lua

index 9b2bed33f0b416a9e22600002c1dc4d670d5e828..4c74b1c5f426c2bf911d19c10b93511bb749c6b4 100644 (file)
@@ -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
 --
index 6d00711445330b3d99d38c84306383858cc4cb72..bfde0a8705957765b40923441f7fc61ea4aea296 100644 (file)
@@ -425,6 +425,12 @@ minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname"
 minetest.get_worldpath(modname) -> eg. "/home/user/.minetest/world"
 ^ Useful for storing custom data
 
+minetest.debug(line)
+^ Goes to dstream
+minetest.log(line)
+minetest.log(loglevel, line)
+^ loglevel one of "error", "action", "info", "verbose"
+
 minetest.register_entity(name, prototype table)
 minetest.register_abm(abm definition)
 minetest.register_node(name, node definition)
@@ -461,11 +467,8 @@ minetest.sound_play(spec, parameters) -> handle
 ^ parameters = sound parameter table
 minetest.sound_stop(handle)
 
-minetest.debug(line)
-^ Goes to dstream
-minetest.log(line)
-minetest.log(loglevel, line)
-^ loglevel one of "error", "action", "info", "verbose"
+minetest.after(time, func)
+^ Call function after time seconds
 
 Global objects:
 minetest.env - environment reference
index e11086274b90d9594895d007165329fc0d49e69c..5dab41354b6fddabf533c75e3dfd9f0561ed2482 100644 (file)
@@ -6,38 +6,18 @@
 
 experimental = {}
 
-timers_to_add = {}
-timers = {}
-minetest.register_globalstep(function(dtime)
-  for indes, timer in ipairs(timers_to_add) do
-    table.insert(timers, timer)
-  end
-  timers_to_add = {}
-  for index, timer in ipairs(timers) do
-    timer.time = timer.time - dtime
-    if timer.time <= 0 then
-      timer.func()
-      timers[index] = nil
-    end
-  end
-end)
-
-after = function(time, func)
-  table.insert(timers_to_add, {time=time, func=func})
-end
-
 --[[
 stepsound = -1
 function test_sound()
        print("test_sound")
        stepsound = minetest.sound_play("default_grass_footstep", {gain=1.0})
-       after(2.0, test_sound)
-       --after(0.1, test_sound_stop)
+       minetest.after(2.0, test_sound)
+       --minetest.after(0.1, test_sound_stop)
 end
 function test_sound_stop()
        print("test_sound_stop")
        minetest.sound_stop(stepsound)
-       after(2.0, test_sound)
+       minetest.after(2.0, test_sound)
 end
 test_sound()
 --]]