Add print command, improve error msg

This commit is contained in:
Joachim Stolberg 2021-05-04 21:21:02 +02:00
parent 3f61f4ab56
commit a2da9f8393
9 changed files with 97 additions and 50 deletions

View File

@ -96,6 +96,7 @@ For all Inventory commands applies: If the inventory stack specified by <slot> i
pattern - save the blocks behind the shield (up to 5x3x3) as template
copy <size> - make a copy of "pattern". Size is e.g. 3x3 (see ingame help)
punch_cart - Punch a rail cart to start it
print <text> - Output chat message for debug purposes
#### Flow control commands
@ -171,4 +172,5 @@ optional: farming redo, node_io, doc, techage, minecart
- 2021-01-30 v1.05 * Many improvements and bugfixes
- 2021-03-14 v1.06 * Switch translation from intllib to minetest.translator
- 2021-04-24 v1.07 * Adapted to minecart v2.0
- 2021-05-04 v1.08 * Add print command, improve error msg

View File

@ -111,7 +111,7 @@ end
local function status(mem)
if mem.error then
return dump(mem.error)
return mem.error
end
if mem.running then
return S("running")

View File

@ -153,11 +153,16 @@ local function activate_sensor(pos, param2)
end
end
local function bot_error(base_pos, mem, err)
local function bot_error(base_pos, mem, err, cmd)
minetest.sound_play('signs_bot_error', {pos = base_pos})
minetest.sound_play('signs_bot_error', {pos = mem.robot_pos})
if cmd then
signs_bot.infotext(base_pos, err .. ":\n'" .. cmd .. "'")
mem.error = err .. ": '" .. cmd .. "'"
else
signs_bot.infotext(base_pos, err)
mem.error = err
end
return false
end
@ -174,9 +179,9 @@ local function power_consumption(mem, cmnd)
end
function signs_bot.run_next_command(base_pos, mem)
local res, err = ci.run_script(base_pos, mem)
local res, err, cmd = ci.run_script(base_pos, mem)
if res == ci.ERROR then
return bot_error(base_pos, mem, err)
return bot_error(base_pos, mem, err, cmd)
elseif res == ci.EXIT then
signs_bot.stop_robot(base_pos, mem)
return false
@ -278,4 +283,22 @@ new program from the sign]]),
end,
})
signs_bot.register_botcommand("print", {
mod = "debug",
params = "<text>",
num_param = 1,
description = S([[Print given text as chat message.
For two or more words, use the '*' character
instead of spaces, like "Hello*world"]]),
check = function(text)
return text ~= ""
end,
cmnd = function(base_pos, mem, text)
text = text:gsub("*", " ")
local owner = M(base_pos):get_string("owner")
if owner ~= "" and text ~= "" then
minetest.chat_send_player(owner, "Bot: " .. text)
end
return signs_bot.DONE
end,
})

View File

@ -15,7 +15,7 @@
signs_bot = {}
-- Version for compatibility checks, see readme.md/history
signs_bot.version = 1.07
signs_bot.version = 1.08
-- Test for MT 5.4 new string mode
signs_bot.CLIP = minetest.features.use_texture_alpha_string_modes and "clip" or true

View File

@ -127,6 +127,19 @@ local function compile(script)
return pass2(tokens)
end
local function gen_string_cmnd(code, pc, num_param, script)
local tokens = tokenizer(script)
if num_param == 0 then
return tokens[pc]
elseif num_param == 1 then
return tokens[pc] .. " " .. tokens[pc+1]
elseif num_param == 2 then
return tokens[pc] .. " " .. tokens[pc+1] .. " " .. tokens[pc+2]
else
return tokens[pc] .. " " .. tokens[pc+1] .. " " .. tokens[pc+2] .. " " .. tokens[pc+3]
end
end
-------------------------------------------------------------------------------
-- Commands
-------------------------------------------------------------------------------
@ -280,7 +293,7 @@ function api.run_script(base_pos, mem)
mem.pc = 1
mem.Stack = {}
end
return res, err
return res, err, gen_string_cmnd(code, mem.pc, num_param, mem.script)
end
return api.EXIT
end

View File

@ -201,7 +201,6 @@ function signs_bot.lib.after_dig_sign_node(pos, oldnode, oldmetadata, digger)
smeta:set_string("err_msg", oldmetadata.fields.err_msg or "")
end
local player_name = digger:get_player_name()
-- See https://github.com/minetest/minetest/blob/34e3ede8eeb05e193e64ba3d055fc67959d87d86/doc/lua_api.txt#L6222
if player_name == "" then
minetest.add_item(pos, sign)
else

View File

@ -43,11 +43,6 @@ Bot Sensor: Not connected=Bot Sensor: Nicht verbunden
The Bot Sensor detects any bot and sends a signal, if a bot is nearby.=Der Roboter Sensor entdeckt jeden Roboter und sendet ein Signal, sofern ein Roboter in der Nähe ist.
The sensor direction does not care.=Die Ausrichtung des Sensor spielt keine Rolle.
### bot_sensor.lua ###
### cart_sensor.lua ###
the sensor range is one node/meter.=Der Sensorbereich ist einen Block/Meter groß.
### cart_sensor.lua ###
Cart Sensor: Connected with=Wagen Sensor: Verbunden mit
@ -56,6 +51,11 @@ Cart Sensor: Not connected=Wagen Sensor: Nicht verbunden
The Cart Sensor detects and sends a signal, if a cart (Minecart) is nearby.=Der Wagen Sensor sendet ein Signal, sofern ein Wagen in der Nähe ist.
The sensor has an active side (red) that must point to the rail/cart.=Der Sensor hat eine aktive Seite (rot), welche zu den Schienen zeigen muss.
### cart_sensor.lua ###
### bot_sensor.lua ###
the sensor range is one node/meter.=Der Sensorbereich ist einen Block/Meter groß.
### changer.lua ###
Signs:=Zeichen:
@ -87,12 +87,6 @@ Sign 'farming'=Zeichen 'Farming'
Used to harvest and seed a 3x3 field.=Benötigt um ein 3x3 Feld zu ernten und wieder zu sähen.
The seed to be placed has to be in the first inventory slot of the bot.=Das Saatgut, dass gesät werden soll, muss sich an der 1. Position im Inventar befinden.
### cmd_farming.lua ###
### cmd_flowers.lua ###
Place the sign in front of the field.=Platziere das Zeichen vor das Feld.
When finished, the bot turns.=Der Roboter dreht um, wenn er fertig ist.
### cmd_flowers.lua ###
Cutting flowers and tree blocks@nin front of the robot@non a 3x3 field.=Schneide Blumen und Baumblöcke@nin einem 3x3 großem Feld@nvor dem Roboter.
@ -100,6 +94,12 @@ Sign "flowers"=Zeichen "Blumen"
Sign 'flowers'=Zeichen 'Blumen'
Used to cut flowers on a 3x3 field.=Benötigt um ein 3x3 Blumenfeld zu ernten.
### cmd_flowers.lua ###
### cmd_farming.lua ###
Place the sign in front of the field.=Platziere das Zeichen vor das Feld.
When finished, the bot turns.=Der Roboter dreht um, wenn er fertig ist.
### cmd_item.lua ###
Take <num> items from a chest like node@nand put it into the item inventory.@n<slot> is the inventory slot (1..8) or 0 for any one=Nehme <num> Gegenstände aus der@nKiste oder dem Kisten-ähnlichen Block@nund tue diese in das eigene Inventar@nan der Position <slot>. Slot = (1..8)@noder 0 für irgend eine Position
@ -195,6 +195,7 @@ return from a subroutine=Rückkehr von einer Unterfunktion
jump to a label=Sprung zu einer Marke
Move the robot 1..999 steps forward@nwithout paying attention to any signs.@nUp and down movements also become@ncounted as steps.=Bewege den Roboter 1..999 Schritte@nvorwärts ohne auf Zeichen zu achten.@nAuf- und Ab-Bewegungen werden auch@nals Schritte gezählt.
Walk until a sign or obstacle is@nreached. Then continue with the next command.@nWhen a sign has been reached, @nthe current program is ended@nand the bot executes the@nnew program from the sign=Gehe bis ein Zeichen oder Hindernis@nerreicht wurde. Führe dann das nächste@nKommando aus. @nWurde ein Zeichen erreicht, so arbeite@ndie Kommandos des Zeichens als@nUnter-Prozess ab
Print given text as chat message.@nFor two or more words, use the '*' character @ninstead of spaces, like "Hello*world"=Gebe den angegebenen Text als Chat-Nachricht aus.@nFür zwei oder mehr Wörter verwende das Zeichen '*' @nanstelle von Leerzeichen, z. B. "Hallo*Welt".
### compost.lua ###
@ -301,8 +302,8 @@ Bot inventory behavior=Verhalten beim Roboter Inventar
### duplicator.lua ###
Input:=Eingabe:
Template:=Vorlage:
Input:=Eingabe:
Output:=Ausgabe:
1. Place one 'cmnd' sign= 1. Kommando Zeichen einlegen
2. Add 'blank signs'=2. Füge 'leere Zeichen' hinzu
@ -344,11 +345,6 @@ inputs=Eingängen
Signal AND=Signal UND
Signal is sent, if all input signals are received.=Signal wird gesendet, wenn all Eingangssignale empfangen wurden.
### logic_and.lua ###
### timer.lua ###
Connected with=Verbunden mit
### node_sensor.lua ###
Node Sensor: Connected with =Block Sensor: Verbunden mit
@ -388,8 +384,8 @@ The Bot takes items out of a minecart in front of it, pushes the cart and then t
Ignite the techage charcoal lighter=Zünde den Holzkohle-Anzünder an
Turns the bot off if the@nbattery power is below the@ngiven value in percent (1..99)=Schalte den Bot aus,@nwenn die Batterieladung kleiner@nist als der angegebene Wert@nin Prozent (1.99)
Sends a techage command@nto a given node.@nReceiver is addressed by@nthe techage node number.=Sende ein techage Kommando@nan einen Block mit der@nangegebenen Blocknummer.
fully charged=voll geladen
Sends a techage command@nto a given node. @nReceiver is addressed by@nthe techage node number.@nFor commands with two or more @nwords, use the '*' character @ninstead of spaces, e.g.: @nsend_cmnd 3465 pull*default:dirt*2=Sende ein techage Kommando@nan einen Block mit der@nangegebenen Blocknummer.@nFür Kommandos mit zwei oder mehr @nWörtern verwende das Zeichen '*' @nanstelle des Leerzeichens, wie bspw.:@nsend_cmnd 3465 pull*default:dirt*2
### timer.lua ###
@ -404,6 +400,11 @@ Can be programmed with a time in seconds, e.g. to start the bot cyclically.=Kann
Start=Start
### timer.lua ###
### logic_and.lua ###
Connected with=Verbunden mit
### tool.lua ###
Sensor Connection Tool=Sensor Verbindungswerkzeug

View File

@ -43,11 +43,6 @@ Bot Sensor: Not connected=
The Bot Sensor detects any bot and sends a signal, if a bot is nearby.=
The sensor direction does not care.=
### bot_sensor.lua ###
### cart_sensor.lua ###
the sensor range is one node/meter.=
### cart_sensor.lua ###
Cart Sensor: Connected with=
@ -56,6 +51,11 @@ Cart Sensor: Not connected=
The Cart Sensor detects and sends a signal, if a cart (Minecart) is nearby.=
The sensor has an active side (red) that must point to the rail/cart.=
### cart_sensor.lua ###
### bot_sensor.lua ###
the sensor range is one node/meter.=
### changer.lua ###
Signs:=
@ -87,12 +87,6 @@ Sign 'farming'=
Used to harvest and seed a 3x3 field.=
The seed to be placed has to be in the first inventory slot of the bot.=
### cmd_farming.lua ###
### cmd_flowers.lua ###
Place the sign in front of the field.=
When finished, the bot turns.=
### cmd_flowers.lua ###
Cutting flowers and tree blocks@nin front of the robot@non a 3x3 field.=
@ -100,6 +94,12 @@ Sign "flowers"=
Sign 'flowers'=
Used to cut flowers on a 3x3 field.=
### cmd_flowers.lua ###
### cmd_farming.lua ###
Place the sign in front of the field.=
When finished, the bot turns.=
### cmd_item.lua ###
Take <num> items from a chest like node@nand put it into the item inventory.@n<slot> is the inventory slot (1..8) or 0 for any one=
@ -195,6 +195,7 @@ return from a subroutine=
jump to a label=
Move the robot 1..999 steps forward@nwithout paying attention to any signs.@nUp and down movements also become@ncounted as steps.=
Walk until a sign or obstacle is@nreached. Then continue with the next command.@nWhen a sign has been reached, @nthe current program is ended@nand the bot executes the@nnew program from the sign=
Print given text as chat message.@nFor two or more words, use the '*' character @ninstead of spaces, like "Hello*world"=
### compost.lua ###
@ -301,12 +302,12 @@ Bot inventory behavior=
### duplicator.lua ###
Input:=
Template:=
Input:=
Output:=
1. Place one 'cmnd' sign to be@n used as template=
2. Add 'blank signs' to@n the input inventory=
3. Take the copies from @n the output inventory=
1. Place one 'cmnd' sign=
2. Add 'blank signs'=
3. Take the copies=
Signs Duplicator=
Sign "user"=
Sign "blank"=
@ -344,11 +345,6 @@ inputs=
Signal AND=
Signal is sent, if all input signals are received.=
### logic_and.lua ###
### timer.lua ###
Connected with=
### node_sensor.lua ###
Node Sensor: Connected with =
@ -388,8 +384,8 @@ The Bot takes items out of a minecart in front of it, pushes the cart and then t
Ignite the techage charcoal lighter=
Turns the bot off if the@nbattery power is below the@ngiven value in percent (1..99)=
Sends a techage command@nto a given node.@nReceiver is addressed by@nthe techage node number.=
fully charged=
Sends a techage command@nto a given node. @nReceiver is addressed by@nthe techage node number.@nFor commands with two or more @nwords, use the '*' character @ninstead of spaces, e.g.: @nsend_cmnd 3465 pull*default:dirt*2=
### timer.lua ###
@ -404,6 +400,11 @@ Can be programmed with a time in seconds, e.g. to start the bot cyclically.=
Start=
### timer.lua ###
### logic_and.lua ###
Connected with=
### tool.lua ###
Sensor Connection Tool=

View File

@ -103,12 +103,20 @@ if minetest.get_modpath("techage") then
mod = "techage",
params = "<receiver> <command>",
num_param = 2,
description = S("Sends a techage command\nto a given node.\nReceiver is addressed by\nthe techage node number."),
description = S([[Sends a techage command
to a given node.
Receiver is addressed by
the techage node number.
For commands with two or more
words, use the '*' character
instead of spaces, e.g.:
send_cmnd 3465 pull*default:dirt*2]]),
check = function(address, command)
address = tonumber(address)
return address ~= nil and command ~= nil and command ~= ""
end,
cmnd = function(base_pos, mem, address, command)
command = command:gsub("*", " ")
address = tostring(tonumber(address))
local meta = minetest.get_meta(base_pos)
local number = meta:get_int("number") or 0