Merge pull request #40 from Thomas--S/touchscreen-adjustments

Necessary adjustments for upcoming Touchscreen mod
master
Joachim Stolberg 2020-11-05 20:57:02 +01:00 committed by GitHub
commit bff2824f2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 83 additions and 65 deletions

View File

@ -1376,9 +1376,9 @@ techage.manual_DE.aText = {
"Wird etwas in die Kiste gelegt\\, oder entnommen\\, oder eine der Tasten \"F1\"/\"F2\" gedrückt\\, so wird ein Event-Signal an den Lua Controller gesendet.\n".. "Wird etwas in die Kiste gelegt\\, oder entnommen\\, oder eine der Tasten \"F1\"/\"F2\" gedrückt\\, so wird ein Event-Signal an den Lua Controller gesendet.\n"..
"Die Sensor Kiste unterstützt folgende Kommandos:\n".. "Die Sensor Kiste unterstützt folgende Kommandos:\n"..
"\n".. "\n"..
" - Über 'state = $read_data(<num>\\, \"state\")' kann der Status der Kiste abgefragt werden. Mögliche Antworten sind: \"empty\"\\, \"loaded\"\\, \"full\"\n".. " - Über 'state = $send_cmnd(<num>\\, \"state\")' kann der Status der Kiste abgefragt werden. Mögliche Antworten sind: \"empty\"\\, \"loaded\"\\, \"full\"\n"..
" - Über 'name\\, action = $read_data(<num>\\, \"action\")' kann die letzte Spieleraktion abgefragt werden. 'name' ist der Spielername\\, Als 'action' wird zurückgeliefert: \"put\"\\, \"take\"\\, \"f1\"\\, \"f2\".\n".. " - Über 'name\\, action = $send_cmnd(<num>\\, \"action\")' kann die letzte Spieleraktion abgefragt werden. 'name' ist der Spielername\\, Als 'action' wird zurückgeliefert: \"put\"\\, \"take\"\\, \"f1\"\\, \"f2\".\n"..
" - Über 'stacks = $read_data(<num>\\, \"stacks\")' kann der Inhalt der Kiste ausgelesen werden. Siehe dazu: https://github.com/joe7575/techage/blob/master/manuals/ta4_lua_controller_EN.md#sensor-chest\n".. " - Über 'stacks = $send_cmnd(<num>\\, \"stacks\")' kann der Inhalt der Kiste ausgelesen werden. Siehe dazu: https://github.com/joe7575/techage/blob/master/manuals/ta4_lua_controller_EN.md#sensor-chest\n"..
" - Über '$send_cmnd(<num>\\, \"text\"\\, \"press both buttons andnput something into the chest\")' kann der Text im Menü der Sensor Kiste gesetzt werden.\n".. " - Über '$send_cmnd(<num>\\, \"text\"\\, \"press both buttons andnput something into the chest\")' kann der Text im Menü der Sensor Kiste gesetzt werden.\n"..
"\n".. "\n"..
"Über die Checkbox \"Erlaube öffentlichen Zugriff\" kann eingestellt werden\\, ob die Kiste von jedem genutzt werden darf\\, oder nur von Spielern die hier Zugriffsrechte haben.\n".. "Über die Checkbox \"Erlaube öffentlichen Zugriff\" kann eingestellt werden\\, ob die Kiste von jedem genutzt werden darf\\, oder nur von Spielern die hier Zugriffsrechte haben.\n"..
@ -1524,7 +1524,7 @@ techage.manual_DE.aText = {
"\n".. "\n"..
"Der Kiste besitzt ein zusätzliches Kommandos für den Lua Controller:\n".. "Der Kiste besitzt ein zusätzliches Kommandos für den Lua Controller:\n"..
"\n".. "\n"..
" - 'count' dient zur Anfrage\\, wie viele Items in der Kiste sind.\nBeispiel 1: '$read_data(CHEST\\, \"count\")' --> Summe der Items über alle 8 Speicher\nBeispiel 2: '$read_data(CHEST\\, \"count\"\\, 2)' --> Anzahl der Items in Speicher 2 (zweiter von links)\n".. " - 'count' dient zur Anfrage\\, wie viele Items in der Kiste sind.\nBeispiel 1: '$send_cmnd(CHEST\\, \"count\")' --> Summe der Items über alle 8 Speicher\nBeispiel 2: '$send_cmnd(CHEST\\, \"count\"\\, 2)' --> Anzahl der Items in Speicher 2 (zweiter von links)\n"..
"\n".. "\n"..
"\n".. "\n"..
"\n", "\n",

View File

@ -1358,9 +1358,9 @@ techage.manual_EN.aText = {
"If something is put into the box or removed\\, or one of the \"F1\" / \"F2\" keys is pressed\\, an event signal is sent to the Lua controller.\n".. "If something is put into the box or removed\\, or one of the \"F1\" / \"F2\" keys is pressed\\, an event signal is sent to the Lua controller.\n"..
"The sensor box supports the following commands:\n".. "The sensor box supports the following commands:\n"..
"\n".. "\n"..
" - The status of the box can be queried via 'state = $read_data(<num>\\, \"state\")'. Possible answers are: \"empty\"\\, \"loaded\"\\, \"full\"\n".. " - The status of the box can be queried via 'state = $send_cmnd(<num>\\, \"state\")'. Possible answers are: \"empty\"\\, \"loaded\"\\, \"full\"\n"..
" - The last player action can be queried via 'name\\, action = $read_data(<num>\\, \"action\")'. 'name' is the player name. One of the following is returned as 'action': \"put\"\\, \"take\"\\, \"f1\"\\, \"f2\".\n".. " - The last player action can be queried via 'name\\, action = $send_cmnd(<num>\\, \"action\")'. 'name' is the player name. One of the following is returned as 'action': \"put\"\\, \"take\"\\, \"f1\"\\, \"f2\".\n"..
" - The contents of the box can be read out via 'stacks = $read_data(<num>\\, \"stacks\")'. See: https://github.com/joe7575/techage/blob/master/manuals/ta4_lua_controller_EN.md#sensor-chest\n".. " - The contents of the box can be read out via 'stacks = $send_cmnd(<num>\\, \"stacks\")'. See: https://github.com/joe7575/techage/blob/master/manuals/ta4_lua_controller_EN.md#sensor-chest\n"..
" - Via '$send_cmnd(<num>\\, \"text\"\\, \"press both buttons andnput something into the chest\")' the text can be set in the menu of the sensor box.\n".. " - Via '$send_cmnd(<num>\\, \"text\"\\, \"press both buttons andnput something into the chest\")' the text can be set in the menu of the sensor box.\n"..
"\n".. "\n"..
"The checkbox \"Allow public chest access\" can be used to set whether the box can be used by everyone or only by players who have access/protection rights here.\n".. "The checkbox \"Allow public chest access\" can be used to set whether the box can be used by everyone or only by players who have access/protection rights here.\n"..
@ -1506,7 +1506,7 @@ techage.manual_EN.aText = {
"\n".. "\n"..
"The chest has an additional command for the Lua controller:\n".. "The chest has an additional command for the Lua controller:\n"..
"\n".. "\n"..
" - 'count' is used to request how many items are in the chest.\nExample 1: '$read_data(CHEST\\, \"count\")' -> Sum of items across all 8 stores\nExample 2: '$read_data(CHEST\\, \"count\"\\, 2)' -> number of items in store 2 (second from left)\n".. " - 'count' is used to request how many items are in the chest.\nExample 1: '$send_cmnd(CHEST\\, \"count\")' -> Sum of items across all 8 stores\nExample 2: '$send_cmnd(CHEST\\, \"count\"\\, 2)' -> number of items in store 2 (second from left)\n"..
"\n".. "\n"..
"\n".. "\n"..
"\n", "\n",

View File

@ -14,6 +14,8 @@
local S = techage.S local S = techage.S
techage.display = {}
local NUM_ROWS = 5 local NUM_ROWS = 5
local RADIUS = 6 local RADIUS = 6
local Param2ToFacedir = {[0] = 0, 0, 3, 1, 2, 0} local Param2ToFacedir = {[0] = 0, 0, 3, 1, 2, 0}
@ -33,7 +35,7 @@ local function lcdlib_bugfix(text_tbl)
return "" return ""
end end
local function display_update(pos, objref) function techage.display.display_update(pos, objref)
pos = vector.round(pos) pos = vector.round(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local text = lcdlib_bugfix(nvm.text) local text = lcdlib_bugfix(nvm.text)
@ -44,7 +46,7 @@ local function display_update(pos, objref)
visual_size = {x=0.94, y=0.94} }) visual_size = {x=0.94, y=0.94} })
end end
local function display_updateXL(pos, objref) function techage.display.display_updateXL(pos, objref)
pos = vector.round(pos) pos = vector.round(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local text = lcdlib_bugfix(nvm.text) local text = lcdlib_bugfix(nvm.text)
@ -55,7 +57,7 @@ local function display_updateXL(pos, objref)
visual_size = {x=0.94*1.9, y=0.94} }) visual_size = {x=0.94*1.9, y=0.94} })
end end
local function on_timer(pos) function techage.display.on_timer(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
mem.ticks = mem.ticks or 0 mem.ticks = mem.ticks or 0
@ -77,7 +79,7 @@ local function on_timer(pos)
return true return true
end end
local lcd_box = { techage.display.lcd_box = {
type = "wallmounted", type = "wallmounted",
wall_top = {-8/16, 15/32, -8/16, 8/16, 8/16, 8/16} wall_top = {-8/16, 15/32, -8/16, 8/16, 8/16, 8/16}
} }
@ -90,13 +92,13 @@ minetest.register_node("techage:ta4_display", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
node_box = lcd_box, node_box = techage.display.lcd_box,
selection_box = lcd_box, selection_box = techage.display.lcd_box,
light_source = 6, light_source = 6,
display_entities = { display_entities = {
["techage:display_entity"] = { depth = 0.42, ["techage:display_entity"] = { depth = 0.42,
on_display_update = display_update}, on_display_update = techage.display.display_update},
}, },
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
@ -114,7 +116,7 @@ minetest.register_node("techage:ta4_display", {
techage.remove_node(pos, oldnode, oldmetadata) techage.remove_node(pos, oldnode, oldmetadata)
end, end,
on_timer = on_timer, on_timer = techage.display.on_timer,
on_place = lcdlib.on_place, on_place = lcdlib.on_place,
on_construct = lcdlib.on_construct, on_construct = lcdlib.on_construct,
on_destruct = lcdlib.on_destruct, on_destruct = lcdlib.on_destruct,
@ -124,7 +126,7 @@ minetest.register_node("techage:ta4_display", {
sounds = default.node_sound_glass_defaults(), sounds = default.node_sound_glass_defaults(),
}) })
local lcd_boxXL = { techage.display.lcd_boxXL = {
type = "fixed", type = "fixed",
fixed = {-0.9, -8/16, -8/16, 0.9, -15/32, 8/16} fixed = {-0.9, -8/16, -8/16, 0.9, -15/32, 8/16}
} }
@ -137,13 +139,13 @@ minetest.register_node("techage:ta4_displayXL", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
node_box = lcd_boxXL, node_box = techage.display.lcd_boxXL,
selection_box = lcd_boxXL, selection_box = techage.display.lcd_boxXL,
light_source = 6, light_source = 6,
display_entities = { display_entities = {
["techage:display_entityXL"] = { depth = 0.42, ["techage:display_entityXL"] = { depth = 0.42,
on_display_update = display_updateXL}, on_display_update = techage.display.display_updateXL},
}, },
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
@ -161,7 +163,7 @@ minetest.register_node("techage:ta4_displayXL", {
techage.remove_node(pos, oldnode, oldmetadata) techage.remove_node(pos, oldnode, oldmetadata)
end, end,
on_timer = on_timer, on_timer = techage.display.on_timer,
on_place = lcdlib.on_place, on_place = lcdlib.on_place,
on_construct = lcdlib.on_construct, on_construct = lcdlib.on_construct,
on_destruct = lcdlib.on_destruct, on_destruct = lcdlib.on_destruct,
@ -189,7 +191,7 @@ minetest.register_craft({
}, },
}) })
local function add_line(pos, payload, cycle_time) function techage.display.add_line(pos, payload, cycle_time)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
nvm.text = nvm.text or {} nvm.text = nvm.text or {}
@ -206,7 +208,7 @@ local function add_line(pos, payload, cycle_time)
table.insert(nvm.text, payload) table.insert(nvm.text, payload)
end end
local function write_row(pos, payload, cycle_time) function techage.display.write_row(pos, payload, cycle_time)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
nvm.text = nvm.text or {} nvm.text = nvm.text or {}
@ -227,7 +229,7 @@ local function write_row(pos, payload, cycle_time)
nvm.text[row] = str nvm.text[row] = str
end end
local function clear_screen(pos, cycle_time) function techage.display.clear_screen(pos, cycle_time)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
mem.ticks = mem.ticks or 0 mem.ticks = mem.ticks or 0
@ -242,11 +244,11 @@ end
techage.register_node({"techage:ta4_display"}, { techage.register_node({"techage:ta4_display"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
if topic == "add" then -- add one line and scroll if necessary if topic == "add" then -- add one line and scroll if necessary
add_line(pos, payload, 1) techage.display.add_line(pos, payload, 1)
elseif topic == "set" then -- overwrite the given row elseif topic == "set" then -- overwrite the given row
write_row(pos, payload, 1) techage.display.write_row(pos, payload, 1)
elseif topic == "clear" then -- clear the screen elseif topic == "clear" then -- clear the screen
clear_screen(pos, 1) techage.display.clear_screen(pos, 1)
end end
end, end,
}) })
@ -254,11 +256,11 @@ techage.register_node({"techage:ta4_display"}, {
techage.register_node({"techage:ta4_displayXL"}, { techage.register_node({"techage:ta4_displayXL"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
if topic == "add" then -- add one line and scroll if necessary if topic == "add" then -- add one line and scroll if necessary
add_line(pos, payload, 2) techage.display.add_line(pos, payload, 2)
elseif topic == "set" then -- overwrite the given row elseif topic == "set" then -- overwrite the given row
write_row(pos, payload, 2) techage.display.write_row(pos, payload, 2)
elseif topic == "clear" then -- clear the screen elseif topic == "clear" then -- clear the screen
clear_screen(pos, 2) techage.display.clear_screen(pos, 2)
end end
end, end,
}) })

View File

@ -631,7 +631,7 @@ techage.register_node({"techage:ta4_lua_controller"}, {
elseif topic == "term" then elseif topic == "term" then
set_input(pos, number, "term", payload) set_input(pos, number, "term", payload)
elseif topic == "msg" then elseif topic == "msg" then
set_input(pos, number, "msg", payload) set_input(pos, number, "msg", {src = src, data = payload})
elseif topic == "state" then elseif topic == "state" then
local running = meta:get_int("running") or STATE_STOPPED local running = meta:get_int("running") or STATE_STOPPED
return techage.StateStrings[running] or "stopped" return techage.StateStrings[running] or "stopped"

View File

@ -108,7 +108,7 @@ local function command(pos, cmnd, player)
if techage.lua_ctlr.not_protected(owner, num) then if techage.lua_ctlr.not_protected(owner, num) then
--output(pos, player..":$ msg "..num.." "..text) --output(pos, player..":$ msg "..num.." "..text)
output(pos, "> msg "..num.." "..text) output(pos, "> msg "..num.." "..text)
techage.send_single(own_number, num, "msg", {src=own_number, text=text}) techage.send_single(own_number, num, "msg", text)
return return
end end
end end
@ -230,26 +230,31 @@ techage.lua_ctlr.register_action("put_term", {
}) })
techage.lua_ctlr.register_function("get_msg", { techage.lua_ctlr.register_function("get_msg", {
cmnd = function(self) cmnd = function(self, raw)
local msg = techage.lua_ctlr.get_msg(self.meta.number) local msg = techage.lua_ctlr.get_msg(self.meta.number)
if msg then if msg then
return msg.src, msg.text local data = msg.data
if not raw then
data = tostring(data or "")
end
return msg.src, data
end end
end, end,
help = ' $get_msg() --> number and text string or nil\n'.. help = ' $get_msg([raw]) --> any value or nil\n'..
' If the optional `raw` parameter is not set or false,\n'..
' the return value is guaranteed to be a string.\n'..
' Read a received messages. Number is the node\n'.. ' Read a received messages. Number is the node\n'..
' number of the sender.\n'.. ' number of the sender.\n'..
' example: num,msg = $get_msg().' ' example: num,msg = $get_msg().'
}) })
techage.lua_ctlr.register_action("send_msg", { techage.lua_ctlr.register_action("send_msg", {
cmnd = function(self, num, text) cmnd = function(self, num, data)
local msg = {src = self.meta.number, text = tostring(text or "")}
if techage.lua_ctlr.not_protected(self.meta.owner, num) then if techage.lua_ctlr.not_protected(self.meta.owner, num) then
techage.send_single(self.meta.number, num, "msg", msg) techage.send_single(self.meta.number, num, "msg", data)
end end
end, end,
help = " $send_msg(num, text)\n".. help = " $send_msg(num, data)\n"..
' Send a message to the controller with number "num".\n'.. ' Send a message to the controller with number "num".\n'..
' example: $send_msg("0123", "test")' ' example: $send_msg("0123", "test")'
}) })

View File

@ -391,9 +391,9 @@ Die TA4 Sensor Kiste dient zum Aufbau von Automatischen Lagern oder Verkaufsauto
Wird etwas in die Kiste gelegt, oder entnommen, oder eine der Tasten "F1"/"F2" gedrückt, so wird ein Event-Signal an den Lua Controller gesendet. Wird etwas in die Kiste gelegt, oder entnommen, oder eine der Tasten "F1"/"F2" gedrückt, so wird ein Event-Signal an den Lua Controller gesendet.
Die Sensor Kiste unterstützt folgende Kommandos: Die Sensor Kiste unterstützt folgende Kommandos:
- Über `state = $read_data(<num>, "state")` kann der Status der Kiste abgefragt werden. Mögliche Antworten sind: "empty", "loaded", "full" - Über `state = $send_cmnd(<num>, "state")` kann der Status der Kiste abgefragt werden. Mögliche Antworten sind: "empty", "loaded", "full"
- Über `name, action = $read_data(<num>, "action")` kann die letzte Spieleraktion abgefragt werden. `name` ist der Spielername, Als `action` wird zurückgeliefert: "put", "take", "f1", "f2". - Über `name, action = $send_cmnd(<num>, "action")` kann die letzte Spieleraktion abgefragt werden. `name` ist der Spielername, Als `action` wird zurückgeliefert: "put", "take", "f1", "f2".
- Über `stacks = $read_data(<num>, "stacks")` kann der Inhalt der Kiste ausgelesen werden. Siehe dazu: https://github.com/joe7575/techage/blob/master/manuals/ta4_lua_controller_EN.md#sensor-chest - Über `stacks = $send_cmnd(<num>, "stacks")` kann der Inhalt der Kiste ausgelesen werden. Siehe dazu: https://github.com/joe7575/techage/blob/master/manuals/ta4_lua_controller_EN.md#sensor-chest
- Über `$send_cmnd(<num>, "text", "press both buttons and\nput something into the chest")` kann der Text im Menü der Sensor Kiste gesetzt werden. - Über `$send_cmnd(<num>, "text", "press both buttons and\nput something into the chest")` kann der Text im Menü der Sensor Kiste gesetzt werden.
Über die Checkbox "Erlaube öffentlichen Zugriff" kann eingestellt werden, ob die Kiste von jedem genutzt werden darf, oder nur von Spielern die hier Zugriffsrechte haben. Über die Checkbox "Erlaube öffentlichen Zugriff" kann eingestellt werden, ob die Kiste von jedem genutzt werden darf, oder nur von Spielern die hier Zugriffsrechte haben.
@ -597,8 +597,8 @@ Die Kiste kann nur von den Spielern genutzt werden, die an diesem Ort auch bauen
Der Kiste besitzt ein zusätzliches Kommandos für den Lua Controller: Der Kiste besitzt ein zusätzliches Kommandos für den Lua Controller:
- `count` dient zur Anfrage, wie viele Items in der Kiste sind. - `count` dient zur Anfrage, wie viele Items in der Kiste sind.
Beispiel 1: `$read_data(CHEST, "count")` --> Summe der Items über alle 8 Speicher Beispiel 1: `$send_cmnd(CHEST, "count")` --> Summe der Items über alle 8 Speicher
Beispiel 2: `$read_data(CHEST, "count", 2)` --> Anzahl der Items in Speicher 2 (zweiter von links) Beispiel 2: `$send_cmnd(CHEST, "count", 2)` --> Anzahl der Items in Speicher 2 (zweiter von links)
[ta4_8x2000_chest|image] [ta4_8x2000_chest|image]

View File

@ -393,9 +393,9 @@ The TA4 sensor box is used to set up automatic warehouses or vending machines in
If something is put into the box or removed, or one of the "F1" / "F2" keys is pressed, an event signal is sent to the Lua controller. If something is put into the box or removed, or one of the "F1" / "F2" keys is pressed, an event signal is sent to the Lua controller.
The sensor box supports the following commands: The sensor box supports the following commands:
- The status of the box can be queried via `state = $read_data(<num>, "state")`. Possible answers are: "empty", "loaded", "full" - The status of the box can be queried via `state = $send_cmnd(<num>, "state")`. Possible answers are: "empty", "loaded", "full"
- The last player action can be queried via `name, action = $read_data(<num>, "action")`. `name` is the player name. One of the following is returned as `action`: "put", "take", "f1", "f2". - The last player action can be queried via `name, action = $send_cmnd(<num>, "action")`. `name` is the player name. One of the following is returned as `action`: "put", "take", "f1", "f2".
- The contents of the box can be read out via `stacks = $read_data(<num>, "stacks")`. See: https://github.com/joe7575/techage/blob/master/manuals/ta4_lua_controller_EN.md#sensor-chest - The contents of the box can be read out via `stacks = $send_cmnd(<num>, "stacks")`. See: https://github.com/joe7575/techage/blob/master/manuals/ta4_lua_controller_EN.md#sensor-chest
- Via `$send_cmnd(<num>, "text", "press both buttons and\nput something into the chest")` the text can be set in the menu of the sensor box. - Via `$send_cmnd(<num>, "text", "press both buttons and\nput something into the chest")` the text can be set in the menu of the sensor box.
The checkbox "Allow public chest access" can be used to set whether the box can be used by everyone or only by players who have access/protection rights here. The checkbox "Allow public chest access" can be used to set whether the box can be used by everyone or only by players who have access/protection rights here.
@ -598,8 +598,8 @@ The chest can only be used by players who can build at this location, i.e. who h
The chest has an additional command for the Lua controller: The chest has an additional command for the Lua controller:
- `count` is used to request how many items are in the chest. - `count` is used to request how many items are in the chest.
Example 1: `$read_data(CHEST, "count")` -> Sum of items across all 8 stores Example 1: `$send_cmnd(CHEST, "count")` -> Sum of items across all 8 stores
Example 2: `$read_data(CHEST, "count", 2)` -> number of items in store 2 (second from left) Example 2: `$send_cmnd(CHEST, "count", 2)` -> number of items in store 2 (second from left)
[ta4_8x2000_chest|image] [ta4_8x2000_chest|image]

View File

@ -346,7 +346,11 @@ In addition to Lua standard function the Lua Controller provides the following f
### Techage Command Functions ### Techage Command Functions
* `$read_data(num, ident, add_data)` - Read any kind of data from another block with the given number _num_. With the `$send_cmnd(num, ident, add_data)` function, you can send commands to and retrieve data from another block with the given number _num_.
The possible commands can be classified in two groups: Commands for reading data and commands for causing an action.
Please note, that this is not a technical distinction, only a logical.
* Reading data
_ident_ specifies the data to be read. _ident_ specifies the data to be read.
_add_data_ is for additional data and normally not needed. _add_data_ is for additional data and normally not needed.
The result is block dependent (see table below): The result is block dependent (see table below):
@ -358,18 +362,21 @@ In addition to Lua standard function the Lua Controller provides the following f
| "state" | one of: "empty", "loaded", "full" | State of a chest or Sensor Chest | | "state" | one of: "empty", "loaded", "full" | State of a chest or Sensor Chest |
| "fuel" | number | fuel value of a fuel consuming block | | "fuel" | number | fuel value of a fuel consuming block |
| "depth" | number | Read the current depth value of a quarry block (1..80) | | "depth" | number | Read the current depth value of a quarry block (1..80) |
| "load" | number | Read the load value in percent (0..100) of a tank, silo, accu, or battery block, or from the Signs Bot Box. Silo and tank return two values: The percentage value and the absolute value in units.<br /> Example: percent, absolute = $read_data("223", "load") | | "load" | number | Read the load value in percent (0..100) of a tank, silo, accu, or battery block, or from the Signs Bot Box. Silo and tank return two values: The percentage value and the absolute value in units.<br /> Example: percent, absolute = $send_cmnd("223", "load") |
| "delivered" | number | Read the current delivered power value of a generator block. A power consuming block (accu) provides a negative value | | "delivered" | number | Read the current delivered power value of a generator block. A power consuming block (accu) provides a negative value |
| "action" | player-name, action-string | only for Sensor Chests | | "action" | player-name, action-string | only for Sensor Chests |
| "stacks" | Array with up to 4 Stores with the inventory content (see example) | only for Sensor Chests | | "stacks" | Array with up to 4 Stores with the inventory content (see example) | only for Sensor Chests |
| "count" | number | Read the item counter of the TA4 Item Detector block | | "count" | number | Read the item counter of the TA4 Item Detector block |
| "count" | number of items | Read the total amount of TA4 chest items. An optional number as `add_data` is used to address only one inventory slot (1..8, from left to right). | | "count" | number of items | Read the total amount of TA4 chest items. An optional number as `add_data` is used to address only one inventory slot (1..8, from left to right). |
| "itemstring" | item string of the given slot | Specific command for the TA4 8x2000 Chest to read the item type (technical name) of one chest slot, specified via `add_data` (1..8).<br />Example: s = $read_data("223", "itemstring", 1) | | "itemstring" | item string of the given slot | Specific command for the TA4 8x2000 Chest to read the item type (technical name) of one chest slot, specified via `add_data` (1..8).<br />Example: s = $send_cmnd("223", "itemstring", 1) |
* `$send_cmnd(num, cmnd, data)` - Send a command to another block. _num_ is the number of the remote block, like "1234". _cmnd_ is the command, _data_ is additional data (see table below): * Causing an action
_num_ is the number of the remote block, like "1234".
_cmnd_ is the command,
_data_ is additional data (see table below):
| cmnd | data | comment | | cmnd | data | comment |
| -------------------------------- | ------------ | ------------------------------------------------------------ | | -------------------------------- | ------------ | ------------------------------------------------------------ |
@ -406,10 +413,14 @@ In contrast the Controller can send text strings to the terminal.
### Further Functions ### Further Functions
Messages are used to transport data between Controllers. Messages are text strings or any other data. Incoming messages are stored in order (up to 10) and can be read one after the other. Messages are used to transport data between Controllers. Messages are always converted to text strings. Incoming messages are stored in order (up to 10) and can be read one after the other.
* `$get_msg()` - Read a received message. The function returns the sender number and the message. (see example "Emails") * `$get_msg()` - Read a received message. The function returns the sender number and the message. (see example "Emails")
* `$send_msg(num, msg)` - Send a message to another Controller. _num_ is the destination number. (see example "Emails") * `$send_msg(num, msg)` - Send a message to another Controller. _num_ is the destination number. (see example "Emails")
Similiar to the concept above you can also exchange arbitrary data. Please note that external devices might also send such data.
* `$get_data()` - Read received data. The function returns the sender number and the data.
* `$send_data(num, data)` - Send data to another Controller. _num_ is the destination number.
* `$chat(text)` - Send yourself a chat message. _text_ is a text string. * `$chat(text)` - Send yourself a chat message. _text_ is a text string.
@ -419,7 +430,7 @@ Messages are used to transport data between Controllers. Messages are text strin
* `$item_description("default:apple")` * `$item_description("default:apple")`
Get the description (item name) for a specified itemstring, e. g. determined via the TA4 8x2000 Chest command `itemstring`: Get the description (item name) for a specified itemstring, e. g. determined via the TA4 8x2000 Chest command `itemstring`:
`str = $read_data("223", "itemstring", 1)` `str = $send_cmnd("223", "itemstring", 1)`
`descr = $item_description(str)` `descr = $item_description(str)`
@ -504,15 +515,15 @@ if ticks % 60 == 0 then
$display(DISPLAY, 1, min.." min") $display(DISPLAY, 1, min.." min")
-- Cactus chest overrun -- Cactus chest overrun
sts = $read_data("1034", "state") -- read pusher status sts = $send_cmnd("1034", "state") -- read pusher status
if sts == "blocked" then $display(DISPLAY, 2, "Cactus full") end if sts == "blocked" then $display(DISPLAY, 2, "Cactus full") end
-- Tree chest overrun -- Tree chest overrun
sts = $read_data("1065", "state") -- read pusher status sts = $send_cmnd("1065", "state") -- read pusher status
if sts == "blocked" then $display(DISPLAY, 3, "Tree full") end if sts == "blocked" then $display(DISPLAY, 3, "Tree full") end
-- Furnace fuel empty -- Furnace fuel empty
sts = $read_data("1544", "state") -- read pusher status sts = $send_cmnd("1544", "state") -- read pusher status
if sts == "standby" then $display(DISPLAY, 4, "Furnace fuel") end if sts == "standby" then $display(DISPLAY, 4, "Furnace fuel") end
end end
``` ```
@ -570,7 +581,7 @@ loop() code:
```lua ```lua
if event then if event then
name = $read_data(SENSOR, "name") name = $send_cmnd(SENSOR, "name")
if name == "" then -- no player arround if name == "" then -- no player arround
$clear_screen(DISPLAY) $clear_screen(DISPLAY)
else else
@ -602,13 +613,13 @@ loop() code:
```lua ```lua
if event and $get_input(SENSOR) == "on" then if event and $get_input(SENSOR) == "on" then
-- read inventory state -- read inventory state
state = $read_data(SENSOR, "state") state = $send_cmnd(SENSOR, "state")
$print("state: "..state) $print("state: "..state)
-- read player name and action -- read player name and action
name, action = $read_data(SENSOR, "action") name, action = $send_cmnd(SENSOR, "action")
$print("action"..": "..name.." "..action) $print("action"..": "..name.." "..action)
-- read inventory content -- read inventory content
stacks = $read_data(SENSOR, "stacks") stacks = $send_cmnd(SENSOR, "stacks")
for i,stack in stacks.next() do for i,stack in stacks.next() do
$print("stack: "..stack.get("name").." "..stack.get("count")) $print("stack: "..stack.get("name").." "..stack.get("count"))
end end