Add debug output to logic block, fix some bugs
This commit is contained in:
parent
692777ec6f
commit
c4247a4434
@ -102,7 +102,7 @@ for _, size in ipairs(SIZES) do
|
||||
physical = false,
|
||||
collide_with_objects = false,
|
||||
pointable = false,
|
||||
static_save = false,
|
||||
static_save = true,
|
||||
visual_size = {x = size, y = 0.05, z = 0.05},
|
||||
glow = 14,
|
||||
shaded = true,
|
||||
|
@ -87,8 +87,19 @@ local function check_num(pos, num, player_name)
|
||||
end
|
||||
end
|
||||
|
||||
local function debug(mem, text)
|
||||
mem.debug = mem.debug or {}
|
||||
if #mem.debug > 20 then
|
||||
table.remove(mem.debug, 1)
|
||||
end
|
||||
local s = string.format("%.3f", techage.SystemTime) .. " s: " .. text
|
||||
table.insert(mem.debug, s)
|
||||
end
|
||||
|
||||
local function send(pos, num, val)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
debug(mem, "(outp) " .. num .. " = " .. val)
|
||||
|
||||
if num == "me" then
|
||||
nvm.outp_tbl = nvm.outp_tbl or {}
|
||||
@ -242,7 +253,7 @@ local function formspec(pos, meta)
|
||||
local inputs, outputs = data(nvm)
|
||||
local bt = nvm.blocking_time or 1
|
||||
return "size[10,8.2]" ..
|
||||
"tabheader[0,0;tab;"..S("Rules") .. "," .. S("Help")..";1;;true]" ..
|
||||
"tabheader[0,0;tab;"..S("Rules") .. "," .. S("Help") .. "," .. S("Debug") .. ";1;;true]" ..
|
||||
"container[0.4,0.1]" ..
|
||||
rules(meta) ..
|
||||
"container_end[]" ..
|
||||
@ -263,10 +274,20 @@ end
|
||||
|
||||
local function formspec_help()
|
||||
return "size[10,8.2]" ..
|
||||
"tabheader[0,0;tab;"..S("Rules") .. "," .. S("Help")..";2;;true]" ..
|
||||
"tabheader[0,0;tab;"..S("Rules") .. "," .. S("Help") .. "," .. S("Debug") .. ";2;;true]" ..
|
||||
"textarea[0.3,0.3;9.9,8.5;;;"..minetest.formspec_escape(HELP).."]"
|
||||
end
|
||||
|
||||
local function formspec_debug(mem)
|
||||
mem.debug = mem.debug or {}
|
||||
local s = table.concat(mem.debug, "\n")
|
||||
return "size[10,8.2]" ..
|
||||
"tabheader[0,0;tab;"..S("Rules") .. "," .. S("Help") .. "," .. S("Debug") .. ";3;;true]" ..
|
||||
"textarea[0.3,0.3;9.9,8.5;;;"..minetest.formspec_escape(s).."]" ..
|
||||
"button[1.5,7.5;3,1;update2;" .. S("Update") .. "]" ..
|
||||
"button[5.6,7.5;3,1;clear;" .. S("Clear") .. "]"
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta3_logic2", {
|
||||
description = S("TA3 Logic Block"),
|
||||
tiles = {
|
||||
@ -302,10 +323,20 @@ minetest.register_node("techage:ta3_logic2", {
|
||||
nvm.blocking_time = tonumber(fields.bt) or 0.1
|
||||
nvm.inp_tbl = {me = "off"}
|
||||
nvm.outp_tbl = {}
|
||||
elseif fields.update2 then
|
||||
local mem = techage.get_mem(pos)
|
||||
meta:set_string("formspec", formspec_debug(mem))
|
||||
elseif fields.clear then
|
||||
local mem = techage.get_mem(pos)
|
||||
mem.debug = {}
|
||||
meta:set_string("formspec", formspec_debug(mem))
|
||||
end
|
||||
|
||||
if fields.tab == "2" then
|
||||
meta:set_string("formspec", formspec_help())
|
||||
elseif fields.tab == "3" then
|
||||
local mem = techage.get_mem(pos)
|
||||
meta:set_string("formspec", formspec_debug(mem))
|
||||
else
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
@ -361,10 +392,13 @@ techage.register_node({"techage:ta3_logic2"}, {
|
||||
|
||||
if src ~= nvm.own_num then
|
||||
if topic == "on" then
|
||||
debug(mem, "(inp) " .. src .. " = on")
|
||||
nvm.inp_tbl[src] = "on"
|
||||
elseif topic == "off" then
|
||||
debug(mem, "(inp) " .. src .. " = off")
|
||||
nvm.inp_tbl[src] = "off"
|
||||
else
|
||||
debug(mem, "(inp) invalid command")
|
||||
return "unsupported"
|
||||
end
|
||||
|
||||
|
@ -25,7 +25,7 @@ local function join_to_string(tbl)
|
||||
end
|
||||
|
||||
local function reset_programmer(itemstack, user, pointed_thing)
|
||||
user:set_attribute("techage_prog_numbers", nil)
|
||||
user:get_meta():set_string("techage_prog_numbers", nil)
|
||||
minetest.chat_send_player(user:get_player_name(), S("[TechAge Programmer] programmer reset"))
|
||||
return itemstack
|
||||
end
|
||||
@ -35,9 +35,9 @@ local function read_number(itemstack, user, pointed_thing)
|
||||
if pos then
|
||||
local number = techage.get_node_number(pos)
|
||||
if number then
|
||||
local numbers = minetest.deserialize(user:get_attribute("techage_prog_numbers")) or {}
|
||||
local numbers = minetest.deserialize(user:get_meta():get_string("techage_prog_numbers")) or {}
|
||||
techage.add_to_set(numbers, number)
|
||||
user:set_attribute("techage_prog_numbers", minetest.serialize(numbers))
|
||||
user:get_meta():set_string("techage_prog_numbers", minetest.serialize(numbers))
|
||||
minetest.chat_send_player(user:get_player_name(), S("[TechAge Programmer] number").." "..number.." read")
|
||||
else
|
||||
minetest.chat_send_player(user:get_player_name(), S("[TechAge Programmer] Unknown node on").." "..minetest.pos_to_string(pos))
|
||||
@ -52,8 +52,8 @@ local function program_numbers(itemstack, placer, pointed_thing)
|
||||
local pos = pointed_thing.under
|
||||
if pos then
|
||||
local meta = M(pos)
|
||||
local numbers = minetest.deserialize(placer:get_attribute("techage_prog_numbers")) or {}
|
||||
placer:set_attribute("techage_prog_numbers", nil)
|
||||
local numbers = minetest.deserialize(placer:get_meta():get_string("techage_prog_numbers")) or {}
|
||||
placer:get_meta():set_string("techage_prog_numbers", nil)
|
||||
local player_name = placer:get_player_name()
|
||||
if meta and meta:get_string("owner") ~= player_name then
|
||||
minetest.chat_send_player(player_name, S("[TechAge Programmer] foreign or unknown node!"))
|
||||
|
@ -49,6 +49,10 @@ local function has_water(pos, facedir)
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, node, clicker, itemstack, pointed_thing)
|
||||
if minetest.is_protected(pos, clicker:get_player_name()) then
|
||||
return
|
||||
end
|
||||
|
||||
local pos2 = vector.add(pos, {x = 0, y = -1, z = 0})
|
||||
local node2 = minetest.get_node(pos2)
|
||||
local pos3, res = has_water(pos2, node2.param2)
|
||||
|
Loading…
Reference in New Issue
Block a user