Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- gridX = (tonumber(args[1])*9)
- gridY = (tonumber(args[1])*9)
- posX = 1
- posY = 1
- facing = 0
- cycles = 0
- function rotate(direction)
- if direction == "R" then
- turtle.turnRight()
- facing=facing+1
- elseif direction == "L" then
- turtle.turnLeft()
- facing = facing-1
- elseif direction == "180" then
- facing = facing+2
- end
- if facing>3 then
- facing=facing-4
- elseif facing<0 then
- facing=facing+4
- end
- end
- function move(blocks)
- for j = 1,blocks do
- turtle.forward()
- if facing == 0 then
- posY=posY+1
- elseif facing == 1 then
- posX=posX+1
- elseif facing == 2 then
- posY=posY-1
- elseif facing == 3 then
- posX=posX+1
- end
- if math.fmod(posY,5)==3 and (facing==0 or facing==2) then
- turtle.placeDown()
- elseif (posY==gridY or posY==1) and (facing==0 or facing==2) then
- turtle.placeDown()
- end
- if ((posY==gridY or posY==1) and (facing==0 or facing==2)) or ((posX==gridX or posx==1) and (facing==1 or facing==3)) then print("break")
- break end
- end
- end
- function nextColumn()
- if facing==0 then
- rotate("R")
- move(5)
- rotate("R")
- elseif facing==2 then
- rotate("L")
- move(5)
- rotate("L")
- end
- end
- function main()
- turtle.select(1)
- rotate("R")
- move(2)
- rotate("L")
- for i = 1,math.floor(gridX/5) do
- move(gridY)
- nextColumn()
- end
- move(gridY)
- if gridX>(posX+2) then
- nextColumn()
- move(gridY)
- end
- if facing==0 then
- rotate("L")
- move(gridX-1)
- rotate("L")
- move(gridY-1)
- rotate("180")
- elseif facing==2 then
- rotate("R")
- move(gridX-1)
- rotate("R")
- end
- end
- local trigger = true;
- while true do
- os.pullEvent("redstone")
- if rs.getInput("back") and trigger then
- cycles=cycles+1
- if cycles==2 then
- main()
- cycles=0
- trigger=false
- end
- elseif not rs.getInput("back") then
- trigger = true
- end
- end
Add Comment
Please, Sign In to add comment