-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.lua
39 lines (39 loc) · 866 Bytes
/
select.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
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 = "select"
end
println("Usage:")
println(name.." <slot>")
println("slot: Index of slot to select")
os.exit()
end
if #args~=1 then
if #args>0 then
println("Incorrect number of arguments.")
end
printUsage()
end
local slot = tonumber(args[1])
local invSize = robot.inventorySize()
if slot==nil then
println("Failed to convert argument to number.")
printUsage()
elseif slot<1 or slot>invSize then
println("Slot index out of bounds.")
println("Allowed: [1.0, "..invSize.."]")
printUsage()
end
robot.select(slot)