diff options
-rw-r--r-- | mesecons_luacontroller/init.lua | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua index 6bc1431..d2033e1 100644 --- a/mesecons_luacontroller/init.lua +++ b/mesecons_luacontroller/init.lua @@ -226,6 +226,21 @@ local getinterrupt = function(pos) return interrupt end +local handle_timer = function(pos, elapsed) + local err = lc_update(pos, {type="timer"}) + if err then print(err) end + return false +end + +local gettimer = function(pos) + local timer = function (time) + if type(time) ~= "number" then return end + local nodetimer = minetest.get_node_timer(pos) + nodetimer:start(time) + end + return timer +end + local create_environment = function(pos, mem, event) -- Gather variables for the environment local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates @@ -237,6 +252,7 @@ local create_environment = function(pos, mem, event) pin = merge_portstates(vports, rports), port = vports, interrupt = getinterrupt(pos), + timer = gettimer(pos), digiline_msgs = {}, digiline_send = function(channel, msg) table.insert(lc_digiline_msgs, {["channel"]=channel, ["msg"]=msg}) @@ -521,7 +537,7 @@ minetest.register_node(nodename, { node_box = nodebox, on_construct = reset_meta, on_receive_fields = function(pos, formname, fields) - if fields.quit then + if not fields.program then return end reset(pos) @@ -530,6 +546,7 @@ minetest.register_node(nodename, { if err then print(err) end reset_meta(pos, fields.code, err) end, + on_timer = handle_timer, sounds = default.node_sound_stone_defaults(), mesecons = mesecons, digiline = digiline, |