Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- manual_min.lua — простой пульт
- local robot = require("robot")
- local component = require("component")
- local sides = require("sides")
- local term = require("term")
- local hasGeo = component.isAvailable("geolyzer")
- local geo = hasGeo and component.geolyzer or nil
- local function help()
- print("Команды:")
- print(" f [n] - вперед (по умолчанию 1)")
- print(" b [n] - назад")
- print(" u [n] - вверх")
- print(" d [n] - вниз")
- print(" tl/tr/ta - влево/вправо/разворот")
- print(" ad/af/au - анализ: вниз/вперед/вверх")
- print(" dumpd - все поля анализа снизу")
- print(" help - помощь")
- print(" exit - выход")
- end
- local function many(fn, n, label)
- n = tonumber(n) or 1
- for i=1,n do
- if not fn() then
- print((label or "шаг") .. " #" .. i .. " не выполнен (мешает блок?)")
- break
- end
- end
- end
- local function analyze(side)
- if not hasGeo then
- print("Нет geolyzer в этом роботе.")
- return
- end
- local d = geo.analyze(side) or {}
- local id = d.name or "nil"
- local label = d.label or ""
- print("ID: "..id.." Label: "..label)
- local sz = d.size or 0
- local mx = d.maxSize or 0
- local gr = d.growth or d.grow or 0
- local ga = d.gain or 0
- local re = d.resistance or d.resist or 0
- if (sz ~= 0) or (gr ~= 0) or (ga ~= 0) or (re ~= 0) then
- print("size="..sz.." max="..mx.." grow="..gr.." gain="..ga.." resist="..re)
- end
- end
- local function dumpDown()
- if not hasGeo then print("Нет geolyzer."); return end
- local d = geo.analyze(sides.down) or {}
- for k,v in pairs(d) do
- print(tostring(k)..": "..tostring(v))
- end
- end
- -- main loop
- term.clear()
- print("Пульт запущен. Введите 'help' для списка команд.")
- while true do
- io.write("> ")
- local line = io.read()
- if not line then break end
- local cmd, arg = line:match("^(%S+)%s*(.*)$")
- cmd = (cmd or ""):lower()
- if cmd == "exit" or cmd == "q" then break
- elseif cmd == "help" or cmd == "h" then help()
- elseif cmd == "f" then many(robot.forward, arg, "вперед")
- elseif cmd == "b" then many(robot.back, arg, "назад")
- elseif cmd == "u" then many(robot.up, arg, "вверх")
- elseif cmd == "d" then many(robot.down, arg, "вниз")
- elseif cmd == "tl" then robot.turnLeft()
- elseif cmd == "tr" then robot.turnRight()
- elseif cmd == "ta" then robot.turnAround()
- elseif cmd == "ad" then analyze(sides.down)
- elseif cmd == "af" then analyze(sides.front)
- elseif cmd == "au" then analyze(sides.up)
- elseif cmd == "dumpd" then dumpDown()
- elseif cmd == "" then -- ignore
- else
- print("Неизвестная команда. help — список команд.")
- end
- end
- print("Выход.")
Advertisement
Add Comment
Please, Sign In to add comment