Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function's Start Here
- function level(x,y)
- -- Turn = 0 ; Turn Right
- -- Turn = 1 ; Turn Left
- x = tonumber(x) -- Converts string to int
- y = tonumber(y) -- Converts string to int
- turn = 0
- myx = 0
- myy = 0
- while ( myy < y) do
- while ( myx < x) do
- turtle.dig()
- turtle.forward()
- myx = myx + 1
- end
- if (myy < (y-1)) then
- if (turn == 0) then
- myx = 0
- myx = myx +1
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- turn = 1
- elseif (turn == 1) then
- myx = 0
- myx = myx +1
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- turn = 0
- else
- print("Error! How did you do that?")
- end
- end
- if (myy < (y-1)) then -- Newly Added
- turtle.forward()
- end
- myy = myy + 1
- end
- -- Turn = 0; Turtle is away from starting location.
- -- Turn = 1; Turtle is close to starting location.
- myx = 0
- myy = 0
- if (turn == 0) then -- Return to starting location
- turtle.turnRight()
- turtle.turnRight()
- turtle.forward()
- while ( myx < (x-2)) do
- turtle.forward()
- myx = myx + 1
- end
- turtle.turnRight()
- while (myy < (y-1)) do
- turtle.forward()
- myy = myy + 1
- end
- turtle.turnLeft() -- This indicates it has returned to it's starting location.
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- elseif (turn == 1) then
- turtle.turnRight()
- while (myy < (y-1)) do
- turtle.forward()
- myy = myy + 1
- end
- turtle.turnLeft() -- This indicates it has returned to it's starting location.
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- else
- print("Error!")
- end
- end
- -- Main Script
- x = 0
- y = 0
- z = 0
- myz = 0
- print("What is x?")
- x = io.read()
- print("What is y?")
- y = io.read()
- print("What is z?")
- z = io.read()
- z = tonumber(z)
- while (myz < z) do
- level(x,y)
- if(myz < (z-1)) then
- turtle.digDown()
- turtle.down()
- end
- myz = myz + 1
- end
- -- Start returning back to surface!
- myz = 0
- while(myz < z) do
- turtle.up()
- myz = myz + 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement