View difference between Paste ID: CN8chJXM and xbrzcxRQ
SHOW: | | - or go back to the newest paste.
1
local tArgs = { ... }
2
if #tArgs ~= 1 then
3
	print( "Usage: stairs <deepth>" )
4
	return
5
end
6
7
local deepth = tArgs[1];
8
9
-- left: 1
10
-- forward: 2
11
-- right: 3
12
13
local direction = 2;
14
local xPos = -1;
15
local yPos = 0;
16
local zPos = 0;
17
18
local function turnLeft()
19
	if (direction == 1) then
20
		return false
21
	end
22-
	turtle.left();
22+
	turtle.turnLeft();
23
	direction = direction - 1;	
24
	return true;
25
end
26
27
local function turnRight()
28
	if (direction == 3) then
29
		return false
30
	end
31-
	turtle.right();
31+
	turtle.turnRight();
32
	direction = direction + 1;
33
	return true;
34
end
35
36
local function perforate()
37
	local result = turtle.dig();
38
	turtle.drop();
39
	os.sleep(0.8);
40
	return result;
41
end
42
43
local function perforate()
44
	local result = turtle.digDown();
45
	turtle.drop();
46
	os.sleep(0.8);
47
	return result;
48
end
49
50
local function advance()
51
	if (turtle.detect()) then
52
		if (not perforate()) then
53
			return false;
54
		end		
55
	end
56
	turtle.forward();
57
	if (direction == 2) then
58
		xPos = xPos + 1;
59
	elseif (direction == 1) then
60
		yPos = yPos - 1;
61
	elseif (direction == 3) then
62
		yPos = yPos + 1;
63
	end		
64
	return true;
65
end
66
67
local function advanceUp()
68
	turtle.up();
69
	zPos = zPos + 1;
70
	return true;
71
end
72
73
local function advanceDown()
74
	if (turtle.detectDown()) then
75
		if (not perforateDown()) then
76
			return false;
77
		end		
78
	end
79
80
	turtle.down();
81
	zPos = zPos - 1;
82
	return true;
83
end
84
85
local blockEnd = true;
86
local done     = false;
87
88
turnRight();
89
90
91
local movement = {}
92
movement[0] = advance;
93
movement[1] = advanceUp;
94
movement[2] = advanceDown;
95
movement[3] = turnLeft;
96
movement[4] = turnRight;
97
98
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};
99
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};
100
101
while (not done) do
102
	local block;
103
	if (isDown) then
104
		block = blockDown;
105
	else
106
		block = blockUp;
107
	end
108
	
109
	for n = 1,#block do
110
		local mov = block[n];
111
		if (not movement[mov]()) then
112
			done = true;
113
			break;
114
		end
115
	end
116
	deepth = deepth - 1;
117
	if (deepth == 0) then
118
		break;
119
	end
120
end
121
122
print("Ended with no errors!");