I know that you can do
turtle.craft()
but I wan't to form the recipe in the turtle…So I figure that you can do
while not turtle.detectDown() do
turtle.down() -- get the turtle down to the ground.
end
turtle.up() -- to keep the turtle 1 block up in the air.
-- I got 2 pieces of log, and I want to craft a chest...
-- The log is in the first position in the turtles inventory
turtle.select(1)
turtle.craft(2)
for i = 1, 9 do -- I THINK this will execute 8 times, starting on 1...
if i == 4 or i == 6 or i == 8 or then i = i + 1 end -- to get the crafting grid for a chest.
if i ~= 8 then turtle.dropDown(8 - i) end -- drop the stuff below the turtle, unless it's on it's 8th run.
if i ~= 1 then turtle.select(i) end -- select the correct slot (not on first run)
if i ~= 8 then turtle.suckDown() end -- pick everything thats below up again, putting it in the expected slot.
end
if not turtle.craft() then
print("Failed crafting!")
end
-- so the turtle should place wooden planks in this pattern:
-- [ ] [ ] [ ]
-- [ ] N/A [ ]
-- [ ] [ ] [ ]
-- unless someone else picks up the blocks or if extra blocks where placed below
⇈ That script should craft me a chest…To be honest, I haven't even tried it. :P/>/>
EDIT: When I tried the code it gave me the error "12: unexpected symbol" (line 12 is in the first if statement in the for loop).
EDIT 2: derp derp, there was an extra or before then.
But is this the correct way to craft with a single crafty turtle?
I can't find in the turtle API a way to move items around inside of the turtle's inventory, or like split the stack…
Pastebin: ZatR8kmB
EDIT 3: So I tried to just write it all down, step by step:
Spoiler
turtle.select(1)
turtle.craft()
turtle.dropDown(7)
turtle.select(2)
turtle.suckDown()
turtle.dropDown(6)
turtle.select(3)
turtle.suckDown()
turtle.dropDown(5)
turtle.select(5)
turtle.suckDown()
turtle.dropDown(4)
turtle.select(7)
turtle.suckDown()
turtle.dropDown(3)
turtle.select(9)
turtle.suckDown()
turtle.dropDown(2)
turtle.select(10)
turtle.suckDown()
turtle.dropDown(1)
turtle.select(11)
turtle.suckDown()
turtle.select(1)
turtle.craft()
The original script got it to this:
[2] [1] [2]
[2] N/A [1]
N/A N/A N/A
and the ugly stepbystep script crafted successfully.So there must be something wrong with the script.
EDIT 4: I did the same thing (kind of) with a while loop!
Spoiler
while not turtle.detectDown() do
if not turtle.down() and turtle.getFuelLevel() <= 1 then
print("Out of fuel... :D/>/>")
end
end
turtle.up()
-- got 2 log in slot 1
turtle.select(1)
turtle.craft(2)
local runTimes = 0
local runTimes2 = 1
while runTimes ~= 8 do
runTimes = runTimes + 1
runTimes2 = runTimes2 + 1
if runTimes2 == 4 or runTimes2 == 8 or runTimes2 == 6 then runTimes2 = runTimes2 + 1 end
if runTimes ~= 8 then turtle.dropDown(8 - runTimes) end
turtle.select(runTimes2)
if runTimes ~= 8 then turtle.suckDown() end
end
turtle.select(1)
if not turtle.craft() then
print("Failed crafting!")
else
print("Successful crafting!")
end
Pastebin: jN7NtaAT
Edit 5: So I made another script, this time using turtle.place() and turtle.dig() instead of turtle.drop() and turtle.suck() (Idea by Cranium! :)/>/> )
Spoiler
-- got 2 log in slot 1
turtle.select(1)
turtle.craft(2)
local z = 0
while turtle.detect() do -- This makes sure that its empty in front of the turtle.
turtle.turnRight()
if z ~= 4 then z = z + 1 end
if z == 4 then
turtle.select(16)
turtle.dig()
turtle.drop()
turtle.select(1)
end
end
local x = 0
for i = 1, 8 do
x = x + 1
if x == 4 or x == 8 or x == 6 then x = x + 1 end
turtle.select(1) -- Instead of turtle.drop() and turtle.suck() we use turtle.place() and turtle.dig()
turtle.place()
turtle.select(x)
turtle.dig()
end
turtle.select(1)
if not turtle.craft() then
print("Failed crafting!")
else
print("Successful crafting!")
end
Pastebin: AzveFNuK