This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
McDonald072's profile picture

Crafting turtle

Started by McDonald072, 06 April 2014 - 09:50 AM
McDonald072 #1
Posted 06 April 2014 - 11:50 AM
This is my first (semi-useful) program. It crafts using tables to get recipes.
The command is "craft <Item name>.
Code:
Spoilerargs = {…}
recipes = {
chest = {
1,1,1,0,
1,0,1,0,
1,1,1,0,
0,0,0,0 },
furnace = {
1,1,1,0,
1,0,1,0,
1,1,1,0,
0,0,0,0 },
pickaxe = {
1,1,1,0,
0,1,0,0,
0,1,0,0,
0,0,0,0 },
}
r = args[1]
if r == "chest" then r = 0
elseif r == "furnace" then r = 1
elseif r == "pickaxe" then r = 2
end
turtle.select(16)
if r == 0 then
print("Please put 8 planks into slot 16.")
while turtle.getItemCount(16) ~= 8 do sleep(0.5) end
print("Crafting…")
for i=1, #recipes.chest do
if i + 1 == 17 then
turtle.craft()
print("Finished.")
return
else
if recipes.chest == 0 then
else
turtle.transferTo(i,1)
end
if turtle.getItemCount(16) == 0 then
turtle.select(15)
end
end
end
elseif r == 1 then
print("Please put 8 cobblestones into slot 16.")
while turtle.getItemCount(16) ~= 8 do sleep(0.5) end
print("Crafting…")
for i=1, #recipes.furnace do
if i + 1 == 17 then
turtle.craft()
print("Finished.")
return
else
if recipes.furnace == 0 then
else
turtle.transferTo(i,1)
end
if turtle.getItemCount(16) == 0 then
turtle.select(15)
end
end
end
elseif r == 2 then
print("Please put 3 head materials in slot 16 and 2 sticks in slot 15.")
while turtle.getItemCount(16) ~= 3 or turtle.getItemCount(15) ~= 2 do sleep(0.5) end
print("Crafting…")
for i=1, #recipes.pickaxe do
if i + 1 == 17 then
turtle.craft()
print("Finished.")
return
else
if recipes.pickaxe == 0 then
turtle.select(i+1)
else
turtle.transferTo(i,1)
end
if turtle.getItemCount(16) == 0 then
turtle.select(15)
end
end
end
end

Damn it, indentation doesn't show up.
Edited on 06 April 2014 - 09:51 AM
civilwargeeky #2
Posted 25 April 2014 - 03:20 AM
Hi, didn't actually try the program (sorry), but wanted to let your know that it is very beneficial to post your code to pastebin.com and put the link here, so that people can quickly download it onto turtles.
Also, some pictures or maybe explanation of how to use the program would be very nice, and make more people want to use the program if it suits them.