local function add_component(name) -- получение прокси компонента
name = component.list(name)() -- получить адрес по имени
if name then -- если есть адрес
return component.proxy(name) -- вернуть прокси
end
end
local robot = add_component('robot')
local generator = add_component('generator')
local go, charging, energy_level, sleep
energy_level = function()
return computer.energy()/computer.maxEnergy()
end
sleep = function(timeout)
local deadline = computer.uptime()+timeout
repeat
computer.pullSignal(deadline-computer.uptime())
until computer.uptime() >= deadline
end
go = function()
robot.swing(3)
robot.move(3)
end
charging = function()
robot.select(1)
generator.insert()
while energy_level() < 0.98 do
sleep(30)
end
end
charging()
for i = 1, 10 do
go()
end