47 lines
1.3 KiB
Lua
47 lines
1.3 KiB
Lua
rednet.open("back")
|
|
|
|
curjob = 69
|
|
while true do
|
|
print("From what index do you want to resume jobs?")
|
|
x = read()
|
|
if tonumber(x) then
|
|
curjob = tonumber(x)
|
|
break
|
|
end
|
|
print("That's not a number.")
|
|
end
|
|
|
|
function getNextJob()
|
|
curjob = curjob + 1
|
|
return curjob - 1
|
|
end
|
|
|
|
while true do
|
|
sender, message, proto = rednet.receive("jobs")
|
|
if not message then
|
|
sleep(0.6)
|
|
else
|
|
--print("> raw: "..message)
|
|
if message == "gibjob" then
|
|
if rs.getInput("top") then
|
|
job = getNextJob()
|
|
rednet.broadcast(tostring(job), "newjob")
|
|
print("Found job request. Offering "..tostring(job))
|
|
end
|
|
else
|
|
-- numberic job is complete
|
|
completejob = tonumber(message)
|
|
fuelused = "??"
|
|
fuelsender, fuelmessage, fuelproto = rednet.receive("fuel")
|
|
if fuelmessage then
|
|
fuelused = fuelmessage
|
|
end
|
|
print("Job "..tostring(completejob).." was completed, "..fuelused.." fuel was used")
|
|
rednet.broadcast("thanks", "jobcomplete")
|
|
log = io.open("jobs.log","a")
|
|
log:write(tostring(completejob),"\n")
|
|
log:close()
|
|
end
|
|
end
|
|
end
|