From f5128886f8c25f7403ca419e52436afd23c0bb8d Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Tue, 16 Jun 2020 19:46:06 +0200 Subject: [PATCH] working pattern example --- digiline.lua | 12 ++++++------ examples/simple_pattern.lua | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/digiline.lua b/digiline.lua index 96eb294..b920e92 100644 --- a/digiline.lua +++ b/digiline.lua @@ -123,7 +123,7 @@ function digibuilder.digiline_effector(pos, _, channel, msg) digilines.receptor_send(pos, digibuilder.digiline_rules, set_channel, { pos = msg.pos, error = true, - message = "place node is unknown: '" .. msg.name .. "'" + message = "place node is unknown: '" .. (msg.name or "") .. "'" }) return end @@ -156,12 +156,12 @@ function digibuilder.digiline_effector(pos, _, channel, msg) end -- place node inworld - minetest.place_node(absolute_pos, place_node) + minetest.log("action", "[digibuilder] " .. owner .. " places node '" .. + place_node.name .. "' at " .. + minetest.pos_to_string(absolute_pos) + ) - if enable_param2 then - -- add param2 info - minetest.swap_node(absolute_pos, place_node) - end + minetest.set_node(absolute_pos, place_node) digilines.receptor_send(pos, digibuilder.digiline_rules, set_channel, { pos = msg.pos, diff --git a/examples/simple_pattern.lua b/examples/simple_pattern.lua index 6c78a7e..cc8e155 100644 --- a/examples/simple_pattern.lua +++ b/examples/simple_pattern.lua @@ -2,7 +2,7 @@ -- pattern, starting at -x/-z local data = { -- x >> - "sdsd", + "sdsdsd", "dsds" -- z \/ } @@ -13,9 +13,9 @@ local nodes = { } -- coordinate offsets -local x_offset = -10 -local y_offset = 1 -local z_offset = -10 +local x_offset = -5 +local y_offset = 2 +local z_offset = -5 -- initial start if event.type == "program" then @@ -26,13 +26,13 @@ end -- timer interrupt if event.type == "interrupt" then - local line = data[mem.line] - if not line then + local line = data[mem.line] + if not line then -- done return end - local char = line:sub(mem.pos, 1) + local char = line:sub(mem.pos, mem.pos) if char == "" then -- next line mem.line = mem.line + 1 @@ -46,16 +46,18 @@ if event.type == "interrupt" then pos = { x=x_offset+mem.pos-1, y=y_offset, z=z_offset+mem.line-1 }, name = nodes[char] }) + end -- callback from digibuilder node if event.type == "digiline" and event.channel == "digibuilder" then - if event.error then + if event.error then -- error state error(event.message) + return end -- next command - mem.line = mem.line + 1 + mem.pos = mem.pos + 1 interrupt(1) end