-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstairs
More file actions
81 lines (66 loc) · 1.26 KB
/
stairs
File metadata and controls
81 lines (66 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
--
-- Constructs stairs down that are 4 high and some given length (by default 5)
--
-- The intention is to build one-wide platforms after every 5 steps down.
--
--------------------
-- Digging Down
--------------------
function dig_step()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.down()
turtle.digDown()
end
function dig_steps( remaining )
if remaining == 0 then return 0 end
local count
if remaining > 5 then
count = 5
else
count = 5 - remaining
end
for i = 1, count, 1 do
dig_step()
end
return remaining - count
end
function dig_platform( remaining )
if remaining == 0 then return 0 end
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
return remaining - 1
end
function descend( steps )
while steps > 0 do
steps = dig_steps( steps )
steps = dig_platform( steps )
end
end
--------------------
-- Turtle Ascension
--------------------
function ascend( steps )
for i = 1, steps, 1 do
if (i % 6) ~= 0 then
turtle.up()
end
turtle.back()
end
end
--------------------
-- Driver
--------------------
local argv = {...}
local count = argv[1] or 10
local steps = tonumber(count)
descend( steps )
ascend( steps )
-- TODO: get argument parsing done
function help()
print("stairs [length=10]")
end