imrskull

crop_test2

Oct 11th, 2025 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. -- manual_min.lua — простой пульт
  2.  
  3. local robot = require("robot")
  4. local component = require("component")
  5. local sides = require("sides")
  6. local term = require("term")
  7.  
  8. local hasGeo = component.isAvailable("geolyzer")
  9. local geo = hasGeo and component.geolyzer or nil
  10.  
  11. local function help()
  12. print("Команды:")
  13. print(" f [n] - вперед (по умолчанию 1)")
  14. print(" b [n] - назад")
  15. print(" u [n] - вверх")
  16. print(" d [n] - вниз")
  17. print(" tl/tr/ta - влево/вправо/разворот")
  18. print(" ad/af/au - анализ: вниз/вперед/вверх")
  19. print(" dumpd - все поля анализа снизу")
  20. print(" help - помощь")
  21. print(" exit - выход")
  22. end
  23.  
  24. local function many(fn, n, label)
  25. n = tonumber(n) or 1
  26. for i=1,n do
  27. if not fn() then
  28. print((label or "шаг") .. " #" .. i .. " не выполнен (мешает блок?)")
  29. break
  30. end
  31. end
  32. end
  33.  
  34. local function analyze(side)
  35. if not hasGeo then
  36. print("Нет geolyzer в этом роботе.")
  37. return
  38. end
  39. local d = geo.analyze(side) or {}
  40. local id = d.name or "nil"
  41. local label = d.label or ""
  42. print("ID: "..id.." Label: "..label)
  43. local sz = d.size or 0
  44. local mx = d.maxSize or 0
  45. local gr = d.growth or d.grow or 0
  46. local ga = d.gain or 0
  47. local re = d.resistance or d.resist or 0
  48. if (sz ~= 0) or (gr ~= 0) or (ga ~= 0) or (re ~= 0) then
  49. print("size="..sz.." max="..mx.." grow="..gr.." gain="..ga.." resist="..re)
  50. end
  51. end
  52.  
  53. local function dumpDown()
  54. if not hasGeo then print("Нет geolyzer."); return end
  55. local d = geo.analyze(sides.down) or {}
  56. for k,v in pairs(d) do
  57. print(tostring(k)..": "..tostring(v))
  58. end
  59. end
  60.  
  61. -- main loop
  62. term.clear()
  63. print("Пульт запущен. Введите 'help' для списка команд.")
  64. while true do
  65. io.write("> ")
  66. local line = io.read()
  67. if not line then break end
  68. local cmd, arg = line:match("^(%S+)%s*(.*)$")
  69. cmd = (cmd or ""):lower()
  70.  
  71. if cmd == "exit" or cmd == "q" then break
  72. elseif cmd == "help" or cmd == "h" then help()
  73.  
  74. elseif cmd == "f" then many(robot.forward, arg, "вперед")
  75. elseif cmd == "b" then many(robot.back, arg, "назад")
  76. elseif cmd == "u" then many(robot.up, arg, "вверх")
  77. elseif cmd == "d" then many(robot.down, arg, "вниз")
  78. elseif cmd == "tl" then robot.turnLeft()
  79. elseif cmd == "tr" then robot.turnRight()
  80. elseif cmd == "ta" then robot.turnAround()
  81.  
  82. elseif cmd == "ad" then analyze(sides.down)
  83. elseif cmd == "af" then analyze(sides.front)
  84. elseif cmd == "au" then analyze(sides.up)
  85. elseif cmd == "dumpd" then dumpDown()
  86.  
  87. elseif cmd == "" then -- ignore
  88. else
  89. print("Неизвестная команда. help — список команд.")
  90. end
  91. end
  92.  
  93. print("Выход.")
  94.  
Advertisement
Add Comment
Please, Sign In to add comment