Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #################################
- -- vars
- -- #################################
- cycleFile = "_cycles"
- dirFile = "_dir"
- dirs = {"down", "up", "north", "south", "west", "east"}
- -- #################################
- -- main
- -- #################################
- while true do
- cycleTimes = 0
- dir = nil
- 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 = tonumber(file.readLine())
- file.close()
- cyclesLeft = cycleTimes - 1
- file = fs.open(cycleFile, "w")
- file.write(cyclesLeft)
- file.close(file)
- print("Cycles left: " .. cyclesLeft)
- print("Dir : " .. dirs[dir + 1])
- sleep(.1)
- shell.run("move " .. dir .. " " .. cycleTimes)
- end
- else
- fs.delete(dirFile)
- fs.delete(cycleFile)
- print("wait for command !")
- dir = read();
- if dir == "up" then
- dir = 1
- elseif dir == "down" then
- dir = 0
- elseif dir == "east" then
- dir = 5
- elseif dir == "west" then
- dir = 4
- elseif dir == "north" then
- dir = 2
- elseif dir == "south" then
- dir = 3
- else
- dir = nil
- end
- if dir ~= nil then
- print("dir : " .. dirs[dir + 1])
- file = fs.open(dirFile, "w")
- file.write(dir)
- file.close(file)
- print("steps?")
- steps = tonumber(read())
- if steps > 0 then
- file = fs.open(cycleFile, "w")
- file.write(steps)
- file.close(file)
- else
- print("invalied steps !")
- end
- end
- end
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement