summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesecons/init.lua22
-rw-r--r--mesecons/internal.lua15
-rw-r--r--mesecons_microcontroller/init.lua31
3 files changed, 22 insertions, 46 deletions
diff --git a/mesecons/init.lua b/mesecons/init.lua
index babfca4..40aa7d9 100644
--- a/mesecons/init.lua
+++ b/mesecons/init.lua
@@ -60,14 +60,13 @@ function mesecon:receptor_on(pos, rules)
end
for i, rule in ipairs(rules) do
- local np = {}
- np.x = pos.x + rule.x
- np.y = pos.y + rule.y
- np.z = pos.z + rule.z
+ local np = {
+ x = pos.x + rule.x,
+ y = pos.y + rule.y,
+ z = pos.z + rule.z}
if mesecon:rules_link(pos, np, rules) then
mesecon:turnon(np, pos)
end
- i=i+1
end
end
@@ -76,17 +75,14 @@ function mesecon:receptor_off(pos, rules)
rules = mesecon:get_rules("default")
end
- local connected = false
-
for i, rule in ipairs(rules) do
- local np = {}
- np.x = pos.x + rule.x
- np.y = pos.y + rule.y
- np.z = pos.z + rule.z
- if mesecon:rules_link(pos, np, rules) and mesecon:connected_to_pw_src(np) == false then
+ local np = {
+ x = pos.x + rule.x,
+ y = pos.y + rule.y,
+ z = pos.z + rule.z}
+ if mesecon:rules_link(pos, np, rules) and not mesecon:connected_to_pw_src(np) then
mesecon:turnoff(np, pos)
end
- i=i+1
end
end
diff --git a/mesecons/internal.lua b/mesecons/internal.lua
index 71b5172..ce43ce5 100644
--- a/mesecons/internal.lua
+++ b/mesecons/internal.lua
@@ -2,23 +2,19 @@
--Receptors
function mesecon:is_receptor_node(nodename)
- local i = 1
for i, receptor in ipairs(mesecon.receptors) do
if receptor.onstate == nodename then
return true
end
- i = i + 1
end
return false
end
function mesecon:is_receptor_node_off(nodename, pos, ownpos)
- local i = 1
for i, receptor in ipairs(mesecon.receptors) do
if receptor.offstate == nodename then
return true
end
- i = i + 1
end
return false
end
@@ -87,7 +83,6 @@ end
function mesecon:deactivate(pos)
local node = minetest.env:get_node(pos)
- local i = 1
for i, action in ipairs(mesecon.actions_off) do
action(pos, node)
end
@@ -95,7 +90,6 @@ end
function mesecon:changesignal(pos)
local node = minetest.env:get_node(pos)
- local i = 1
for i, action in ipairs(mesecon.actions_change) do
action(pos, node)
end
@@ -189,7 +183,6 @@ end
function mesecon:turnon(pos)
local node = minetest.env:get_node(pos)
- local i = 1
if mesecon:is_conductor_off(node.name) then
local rules = mesecon:conductor_get_rules(node)
@@ -215,7 +208,6 @@ end
function mesecon:turnoff(pos) --receptor rules used because output could have been dug
local node = minetest.env:get_node(pos)
- local i = 1
local rules
if mesecon:is_conductor_on(node.name) then
@@ -246,7 +238,7 @@ function mesecon:connected_to_pw_src(pos, checked)
local c = 1
if checked == nil then checked = {} end
while checked[c] ~= nil do --find out if node has already been checked (to prevent from endless loop)
- if compare_pos(checked[c], pos) then
+ if compare_pos(checked[c], pos) then
return false, checked
end
c = c + 1
@@ -265,7 +257,6 @@ function mesecon:connected_to_pw_src(pos, checked)
local connected
local rules = mesecon:conductor_get_rules(node)
- local i = 1
for i, rule in ipairs(rules) do
local np = {}
np.x = pos.x + rule.x
@@ -417,7 +408,6 @@ end
--Rules rotation Functions:
function mesecon:rotate_rules_right(rules)
- local i=1
local nr={};
for i, rule in ipairs(rules) do
nr[i]={}
@@ -429,7 +419,6 @@ function mesecon:rotate_rules_right(rules)
end
function mesecon:rotate_rules_left(rules)
- local i=1
local nr={};
for i, rule in ipairs(rules) do
nr[i]={}
@@ -441,7 +430,6 @@ function mesecon:rotate_rules_left(rules)
end
function mesecon:rotate_rules_down(rules)
- local i=1
local nr={};
for i, rule in ipairs(rules) do
nr[i]={}
@@ -453,7 +441,6 @@ function mesecon:rotate_rules_down(rules)
end
function mesecon:rotate_rules_up(rules)
- local i=1
local nr={};
for i, rule in ipairs(rules) do
nr[i]={}
diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua
index 3a2ce2b..59269b3 100644
--- a/mesecons_microcontroller/init.lua
+++ b/mesecons_microcontroller/init.lua
@@ -72,6 +72,7 @@ minetest.register_node(nodename, {
"button_exit[3.5,1;2,3;program;Program]")
meta:set_string("infotext", "Unprogrammed Microcontroller")
meta:set_int("heat", 0)
+ meta:set_int("working", 0)
local r = ""
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
meta:set_string("eeprom", r)
@@ -181,12 +182,15 @@ function yc_code_remove_commentary(code)
end
function yc_parsecode(code, pos)
+ local meta = minetest.env:get_meta(pos)
+ if meta:get_int("working") == 1 then return false end
+ meta:set_int("working", 1)
local endi = 1
local Lreal = yc_get_real_portstates(pos)
local Lvirtual = yc_get_virtual_portstates(pos)
if Lvirtual == nil then return nil end
local c
- local eeprom = minetest.env:get_meta(pos):get_string("eeprom")
+ local eeprom = meta:get_string("eeprom")
while true do
command, endi = parse_get_command(code, endi)
if command == nil then return nil end
@@ -231,6 +235,7 @@ function yc_parsecode(code, pos)
minetest.env:get_meta(pos):set_string("eeprom", eeprom) end
end
yc_action(pos, Lvirtual)
+ minetest.env:get_meta(pos):set_int("working", 0)
return true
end
@@ -569,29 +574,17 @@ end
--Real I/O functions
function yc_action(pos, L) --L-->Lvirtual
- Lv = yc_get_virtual_portstates(pos)
- local meta = minetest.env:get_meta(pos)
- local code = meta:get_string("code")
- local afterid = meta:get_int("afterid")
- local heat = meta:get_int("heat")
- local eeprom = meta:get_string("eeprom")
- local infotext = meta:get_string("infotext")
- local formspec = meta:get_string("formspec")
+ local Lv = yc_get_virtual_portstates(pos)
+ local metatable = minetest.env:get_meta(pos):to_table()
local name = "mesecons_microcontroller:microcontroller"
..tonumber(L.d and 1 or 0)
..tonumber(L.c and 1 or 0)
..tonumber(L.b and 1 or 0)
..tonumber(L.a and 1 or 0)
minetest.env:add_node(pos, {name=name})
- local meta = minetest.env:get_meta(pos)
- meta:set_string("code", code)
- meta:set_int("heat", heat)
- meta:set_int("afterid", afterid)
- meta:set_string("eeprom", eeprom)
- meta:set_string("infotext", infotext)
- meta:set_string("formspec", formspec)
+ minetest.env:get_meta(pos):from_table(metatable)
- yc_action_setports(pos, L, Lv, rules)
+ yc_action_setports(pos, L, Lv)
end
function yc_action_setports(pos, L, Lv)
@@ -602,7 +595,7 @@ function yc_action_setports(pos, L, Lv)
if L.a == true then mesecon:receptor_on(pos, rules)
else mesecon:receptor_off(pos, rules) end
end
- if Lv.b ~= L.b then
+ if Lv.b ~= L.b then
rules = mesecon:get_rules(name.."0010")
if L.b == true then mesecon:receptor_on(pos, rules)
else mesecon:receptor_off(pos, rules) end
@@ -692,7 +685,7 @@ end
function yc_overheat_off(pos)
rules = mesecon:get_rules("mesecons_microcontroller:microcontroller1111")
- mesecon:receptor_off(pos, rules);
+ mesecon:receptor_off(pos, rules)
end
mesecon:register_on_signal_change(function(pos, node)