Advertisement
bob558

Туда-сюда -заправка

Nov 9th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | None | 0 0
  1.  
  2.  
  3. local computer = require('computer')
  4. local robot = require("robot")
  5.  
  6. if require("component").isAvailable("generator")
  7.     then
  8.     generator=require("component").generator
  9. end
  10. local withg=(generator~=nil)
  11.  
  12.  
  13.  
  14. function energy() return computer.energy()<((computer.maxEnergy()*70)/100) end
  15.  
  16. function charg()
  17.   print("Уровень энергии." ,computer.energy())
  18.   if (energy()) then
  19.     refuel()
  20.   end
  21.   if (computer.energy())<((computer.maxEnergy()*30)/100) then
  22.     print("меньше 30 %")
  23.     --while (computer.energy()) >=((computer.maxEnergy()*70)/100) do
  24.     while energy() do
  25.       for i=1, 10 do
  26.         os.sleep(20)
  27.         print("Ожидаю ",(10*i)..'%')
  28.       end
  29.     end
  30.   end
  31. end
  32.  
  33. function refuel() -- Заправка генератора
  34.     for invfuel=1,16 do
  35.         robot.select(invfuel)
  36.         generator.insert(33)
  37.         if generator.count() >= 32 then
  38.           print("заправка зевершена")
  39.           print("топлива в генераторе = "..generator.count())
  40.           do break end
  41.         end
  42.     end
  43. end
  44.  
  45.  
  46. while true do
  47.  
  48. robot.forward()
  49. robot.forward()
  50. robot.forward()
  51. robot.turnAround()
  52.  
  53. robot.forward()
  54. robot.forward()
  55. robot.forward()
  56. charg()
  57. robot.turnAround()
  58.  
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement