diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-04-29 19:13:15 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-04-29 19:13:15 +0200 |
commit | 331db7ba5f4e4b308c1f8efa93c2b40c5139766d (patch) | |
tree | c9dc5d02d6c1986ef420004f94154c61be0cc1a9 /advtrains/advtrains_luaautomation/init.lua | |
parent | 337db2a573ccaa1672e713855022e96106679803 (diff) | |
download | advtrains-331db7ba5f4e4b308c1f8efa93c2b40c5139766d.tar.gz advtrains-331db7ba5f4e4b308c1f8efa93c2b40c5139766d.tar.bz2 advtrains-331db7ba5f4e4b308c1f8efa93c2b40c5139766d.zip |
Unify globalstep, load and save of all components into single functions
Diffstat (limited to 'advtrains/advtrains_luaautomation/init.lua')
-rw-r--r-- | advtrains/advtrains_luaautomation/init.lua | 44 |
1 files changed, 20 insertions, 24 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) |