-- index
-- repeat
-local automata = periperal.wrap("left")
+local automata = peripheral.wrap("left")
local shears =
{ "alloyed:steel_shears"
-- returns the first empty slot
-- if no empty slot is found, returns nil
local findEmpty = function()
- for i = 1, 16 do if not turtle.getItemDetail() then return i end end
+ for i = 1, 16 do if not turtle.getItemDetail(i) then return i end end
return false, "No empty slot"
end
-- select first slot containing an item from list t if not already selected.
-- returns bool.
local select = function(t)
- local item = getItemDetail()
+ local item = turtle.getItemDetail()
if item and oneOf(t, item.name) then
return true
else
-- (this function exists because weak automata cannot digBlock with tools in slots >9)
local transferAndSelect = function(i, t)
local msg = "Could not transfer and select: "
- if i < 1 or i > 16 then return false, msg .. "Index out of range"
+ if i < 1 or i > 16 then return false, msg .. "Index out of range" end
local i_tmp, e = findEmpty()
if not i_tmp then return false, msg .. e end
local i_from, e = find(t)
turtle.transferTo(i_tmp)
turtle.select(i_from)
turtle.transferTo(i)
- turtle.select(i_tmp)
- turtle.transferTo(i_from)
+-- turtle.select(i_tmp)
+-- turtle.transferTo(i_from)
end
turtle.select(i)
return true
end
+-- commands as strings
+-- chars corresponds to actions, when immediatel followed by a number, repeats the action that many times
+-- "udfblrh" = up -> down -> forward -> backward -> turn left -> turn right -> harvest
+-- "u15r" = 15x up -> turn right
+-- "u15 r" = 15x up -> turn right
+-- "u1 5r" = invalid
+
+-- runCommand : string -> true | false message
+local runCommand = function(str)
+ local cmd, n, rest = string.match(string.gsub(str, "^%s+", ""), "^(%w)(%d*)(.+)")
+ if n == "" then n = 1 else n = tonumber(n) end
+ for i = 1, n do
+ print(cmd, tostring(i).."/"..tostring(n))
+ end
+ runCommand(rest)
+end
+
-- for testing purposes
+
+local sequence = function()
+ print("pretending to unload stray items")
+ print("pretending to refuel")
+ print("pretending to stock up on shears")
+ local cmd = "rf4h"
+ print(cmd)
+ runCommand(cmd)
+end
+
while true do
local _, key = os.pullEvent("key")
if key == 72 then -- h
turtle.up()
elseif key == 340 then -- Shift, down
turtle.down()
+ elseif key == 257 then -- Enter, run sequence
+ print("Is the turtle indexed properly?\n(press y to confirm)")
+ local _, char = os.pullEvent("char")
+ if char = "y" then sequence() else print("Aborted") end
end
end