Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: stairs <deepth>" )
- return
- end
- local deepth = tArgs[1];
- -- left: 1
- -- forward: 2
- -- right: 3
- local direction = 2;
- local xPos = -1;
- local yPos = 0;
- local zPos = 0;
- local function turnLeft()
- if (direction == 1) then
- return false
- end
- turtle.turnLeft();
- direction = direction - 1;
- return true;
- end
- local function turnRight()
- if (direction == 3) then
- return false
- end
- turtle.turnRight();
- direction = direction + 1;
- return true;
- end
- local function perforate()
- local result = turtle.dig();
- turtle.drop();
- os.sleep(0.8);
- return result;
- end
- local function perforate()
- local result = turtle.digDown();
- turtle.drop();
- os.sleep(0.8);
- return result;
- end
- local function advance()
- if (turtle.detect()) then
- if (not perforate()) then
- return false;
- end
- end
- turtle.forward();
- if (direction == 2) then
- xPos = xPos + 1;
- elseif (direction == 1) then
- yPos = yPos - 1;
- elseif (direction == 3) then
- yPos = yPos + 1;
- end
- return true;
- end
- local function advanceUp()
- turtle.up();
- zPos = zPos + 1;
- return true;
- end
- local function advanceDown()
- if (turtle.detectDown()) then
- if (not perforateDown()) then
- return false;
- end
- end
- turtle.down();
- zPos = zPos - 1;
- return true;
- end
- local blockEnd = true;
- local done = false;
- turnRight();
- local movement = {}
- movement[0] = advance;
- movement[1] = advanceUp;
- movement[2] = advanceDown;
- movement[3] = turnLeft;
- movement[4] = turnRight;
- local blockUp = {3,0,2,3,0,0,0,4,4,1,0,0,0,3,3,1,0,0,0,4,4,1,0,0,0};
- local blockDown = {3,2,0,3,0,0,0,2,4,4,0,0,0,2,3,3,0,0,0,2,4,4,0,0,0};
- while (not done) do
- local block;
- if (isDown) then
- block = blockDown;
- else
- block = blockUp;
- end
- for n = 1,#block do
- local mov = block[n];
- if (not movement[mov]()) then
- done = true;
- break;
- end
- end
- deepth = deepth - 1;
- if (deepth == 0) then
- break;
- end
- end
- print("Ended with no errors!");
Advertisement
Add Comment
Please, Sign In to add comment