Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local floor = 1
- local pulses = 0
- local timer
- local function goToFloor(n)
- print("Going to floor " .. n)
- turtle.refuel()
- while floor ~= n do
- if n > floor then
- repeat turtle.up() until rs.getInput("back")
- floor = floor + 1
- elseif n < floor then
- repeat turtle.down() until rs.getInput("back")
- floor = floor - 1
- else break end
- end
- redstone.setOutput("left", true)
- local file = fs.open("floor.txt", "w")
- file.writeLine(floor)
- file.close()
- sleep(0.4)
- redstone.setOutput("left", false)
- end
- redstone.setOutput("right", true)
- redstone.setOutput("left", false)
- if fs.exists("floor.txt") then
- local file = fs.open("floor.txt", "r")
- floor = tonumber(file.readLine()) or floor
- file.close()
- end
- while true do
- local ev = {os.pullEvent()}
- if ev[1] == "redstone" and redstone.getInput("front") then
- if timer then os.cancelTimer(timer) end
- timer = os.startTimer(2)
- pulses = pulses + 1
- elseif ev[1] == "timer" and ev[2] == timer then
- timer = nil
- goToFloor(pulses)
- pulses = 0
- end
- end
Add Comment
Please, Sign In to add comment