aboutsummaryrefslogtreecommitdiff
path: root/advtrains/advtrains_luaautomation
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/advtrains_luaautomation')
-rw-r--r--advtrains/advtrains_luaautomation/init.lua44
-rw-r--r--advtrains/advtrains_luaautomation/interrupt.lua2
2 files changed, 21 insertions, 25 deletions
diff --git a/advtrains/advtrains_luaautomation/init.lua b/advtrains/advtrains_luaautomation/init.lua
index 71808e7..b24bc01 100644
--- a/advtrains/advtrains_luaautomation/init.lua
+++ b/advtrains/advtrains_luaautomation/init.lua
@@ -40,25 +40,28 @@ dofile(mp.."/chatcmds.lua")
local filename=minetest.get_worldpath().."/advtrains_luaautomation"
-local file, err = io.open(filename, "r")
-if not file then
- minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": "..(err or "Unknown Error"))
-else
- atprint("luaautomation reading file:",filename)
- local tbl = minetest.deserialize(file:read("*a"))
- if type(tbl) == "table" then
- if tbl.version==1 then
- for envname, data in pairs(tbl.envs) do
- atlatc.envs[envname]=atlatc.env_load(envname, data)
+
+function atlatc.load()
+ local file, err = io.open(filename, "r")
+ if not file then
+ minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": "..(err or "Unknown Error"))
+ else
+ atprint("luaautomation reading file:",filename)
+ local tbl = minetest.deserialize(file:read("*a"))
+ if type(tbl) == "table" then
+ if tbl.version==1 then
+ for envname, data in pairs(tbl.envs) do
+ atlatc.envs[envname]=atlatc.env_load(envname, data)
+ end
+ atlatc.active.load(tbl.active)
+ atlatc.interrupt.load(tbl.interrupt)
+ atlatc.pcnaming.load(tbl.pcnaming)
end
- atlatc.active.load(tbl.active)
- atlatc.interrupt.load(tbl.interrupt)
- atlatc.pcnaming.load(tbl.pcnaming)
+ else
+ minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": Not a table!")
end
- else
- minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": Not a table!")
+ file:close()
end
- file:close()
end
-- run init code of all environments
@@ -94,21 +97,14 @@ atlatc.save = function()
file:close()
end
-minetest.register_on_shutdown(atlatc.save)
-- globalstep for step code
local timer, step_int=0, 2
-local stimer, sstep_int=0, 10
-minetest.register_globalstep(function(dtime)
+function atlatc.mainloop_stepcode(dtime)
timer=timer+dtime
if timer>step_int then
timer=0
atlatc.run_stepcode()
end
- stimer=stimer+dtime
- if stimer>sstep_int then
- stimer=0
- atlatc.save()
- end
end)
diff --git a/advtrains/advtrains_luaautomation/interrupt.lua b/advtrains/advtrains_luaautomation/interrupt.lua
index 4d59db5..fa340b8 100644
--- a/advtrains/advtrains_luaautomation/interrupt.lua
+++ b/advtrains/advtrains_luaautomation/interrupt.lua
@@ -21,7 +21,7 @@ function iq.add(t, pos, evtdata)
run=true
end
-minetest.register_globalstep(function(dtime)
+function iq.mainloop(dtime)
if run then
timer=timer + math.min(dtime, 0.2)
for i=1,#queue do