-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdown.lua
56 lines (56 loc) · 1.05 KB
/
down.lua
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
local args = {...}
local term = require("term")
local robot = require("robot")
local function println(s)
if s then
term.write(s.."\n")
else
term.write("\n")
end
end
local function printUsage()
local name = debug.getinfo(2,"S").short_src:match("[^/]+.lua$")
if name then
name = name:sub(0,-5)
else
name = "down"
end
println("Usage:")
println(name.." <d>")
println("d: Number of spaces to move down")
os.exit()
end
local d
if #args==0 then
d = 1
else
if #args~=1 then
println("Incorrect number of arguments.")
printUsage()
end
d = tonumber(args[1])
if d==nil then
println("Failed to convert argument to number.")
printUsage()
elseif d<=0 then
println("Please provide a positive argument.")
printUsage()
end
end
local function down()
for i=1,60,1 do
if robot.detectDown() then
robot.swingDown()
end
if robot.down() then
return true
end
os.sleep(0.5)
end
return false
end
local x = 0
while x<d and down() do
x = x+1
end
println("Moved down "..x.." block(s).")