Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #################################
- -- vars
- -- #################################
- cycleFile = "_cycles"
- dirFile = "_dir"
- -- #################################
- -- main
- -- #################################
- while true do
- rednet.close("back")
- cycleTimes = 0
- dir = "none"
- if fs.exists(cycleFile) then
- file = fs.open(cycleFile, "r")
- cycleTimes = tonumber(file.readLine())
- file.close()
- end
- if cycleTimes > 0 then
- if fs.exists(dirFile) then
- file = fs.open(dirFile, "r")
- dir = file.readLine()
- file.close()
- cyclesLeft = cycleTimes - 1
- file = fs.open(cycleFile, "w")
- file.write(cyclesLeft)
- file.close(file)
- print("Cycles left: " .. cyclesLeft)
- print("Dir : " .. dir)
- sleep(.1)
- shell.run("move " .. dir .. " " .. cycleTimes)
- end
- else
- fs.delete(dirFile)
- fs.delete(cycleFile)
- rednet.open("back")
- print("wait for message !")
- id, msg, dist = rednet.receive()
- print("message received !")
- if msg == "move up!" then
- dir = "up"
- print("valide action " .. msg .. " !")
- elseif msg == "move down!" then
- dir = "down"
- print("valide action " .. msg .. " !")
- else
- print("invalide action " .. msg .. " !")
- end
- if dir ~= "none" then
- print("dir : " .. dir)
- file = fs.open(dirFile, "w")
- file.write(dir)
- file.close(file)
- print("ask for steps !")
- rednet.send(id, "steps?")
- print("wait for answer ...")
- id, msg, dist = rednet.receive(10)
- if msg ~= nil and tonumber(msg) > 0 then
- print("answer " .. msg .." !")
- cycleTimes = tonumber(msg)
- file = fs.open(cycleFile, "w")
- file.write(cycleTimes)
- file.close(file)
- else
- print("no or invalide answer !")
- end
- end
- end
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement