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

Crafting Turtle Help

Started by CastleMan2000, 29 September 2012 - 02:26 PM
CastleMan2000 #1
Posted 29 September 2012 - 04:26 PM
Hello. I am trying to make a turtle program that gets items from a chest, puts them in the right places, and crafts a new item. Problem: They keep stacking similar items and they don't keep items in the right location.

Here is the setup for the crafty turtle, and the code:

CTC


turtle.turnLeft()
turtle.select(1)
local selectNum = {1,2,3,5,6,7,9,10,11}
for i,v in ipairs(selectNum) do
  turtle.suck()
  turtle.select(v)
end
turtle.turnRight()
turtle.select(1)
turtle.craft(1)
turtle.turnRight()
turtle.drop()
turtle.turnLeft()

Could someone help please?
Doyle3694 #2
Posted 29 September 2012 - 06:07 PM
Your code just makes no sence to me…
Anonomit #3
Posted 29 September 2012 - 06:09 PM
Hello. I am trying to make a turtle program that gets items from a chest, puts them in the right places, and crafts a new item. Problem: They keep stacking similar items and they don't keep items in the right location.

Here is the setup for the crafty turtle, and the code:

CTC


turtle.turnLeft()
turtle.select(1)
local selectNum = {1,2,3,5,6,7,9,10,11}
for i,v in ipairs(selectNum) do
  turtle.suck()
  turtle.select(v)
end
turtle.turnRight()
turtle.select(1)
turtle.craft(1)
turtle.turnRight()
turtle.drop()
turtle.turnLeft()

Could someone help please?


Well, to start with, you skipped the numbers 4 and 8.
I'm not really sure what you're asking, but maybe this will help explain turtle crafting.


turtle.turnLeft()

--this is where the turtle gets items from the chest to craft with
turtle.select(1) --selects slot 1
turtle.suck() --sucks item into slot 1
turtle.drop(turtle.getItemCount(1)-1) --drops all but 1 items back into chest

turtle.select(5) --selects slot 5, right underneath slot 1
turtle.suck() --sucks item into slot 5
turtle.drop(turtle.getItemCount(5)-1) --drops all but 1 item back into chest

--this is where turtle will craft
turtle.turnRight()
turtle.select(1) --selects slot 1
turtle.craft(1) --crafts item and places crafted item in selected slot
turtle.turnRight()
turtle.drop()
turtle.turnLeft()

If the items that the turtle sucked from the chest were wooden planks, then the turtle will craft sticks.
CastleMan2000 #4
Posted 29 September 2012 - 06:28 PM
I skipped 4 and 8 because they were not part of the grid.

1 2 3 4
5 6 7 8
9 A B C
D E F G

I updated the code, and it almost preserves slots, but because turtle.suck is not selective, when I try to craft a furnace I get this inventory in the turtle.

CCC
CCC
CCX

This is the updated code:

Spoiler
turtle.turnLeft()
turtle.select(1)
local selectNum = {1,2,3,5,6,7,9,10,11}

for i,v in ipairs(selectNum) do
  turtle.select(v)
  turtle.suck()
  if turtle.getItemCount(v) >= 1 then
	turtle.drop(turtle.getItemCount(v) - 1)
  end
end

turtle.turnRight()
turtle.select(1)
turtle.craft(1)
turtle.turnRight()
turtle.drop()
turtle.turnLeft()
Anonomit #5
Posted 29 September 2012 - 06:46 PM
I skipped 4 and 8 because they were not part of the grid.

1 2 3 4
5 6 7 8
9 A B C
D E F G

I updated the code, and it almost preserves slots, but because turtle.suck is not selective, when I try to craft a furnace I get this inventory in the turtle.

CCC
CCC
CCX

This is the updated code:

Spoiler
turtle.turnLeft()
turtle.select(1)
local selectNum = {1,2,3,5,6,7,9,10,11}

for i,v in ipairs(selectNum) do
  turtle.select(v)
  turtle.suck()
  if turtle.getItemCount(v) >= 1 then
	turtle.drop(turtle.getItemCount(v) - 1)
  end
end

turtle.turnRight()
turtle.select(1)
turtle.craft(1)
turtle.turnRight()
turtle.drop()
turtle.turnLeft()

I'm not actually updated to CC 1.4+ right now, so none of my code I post here is actually tested.

Spoiler
turtle.turnLeft()
turtle.select(1)
local selectNum = {1,2,3,5,6,7,9,10,11}

for i,v in ipairs(selectNum) do
  turtle.select(v)
  if i ~= 6 then
	turtle.suck()
	if turtle.getItemCount(v) >= 1 then
	  turtle.drop(turtle.getItemCount(v) - 1)
	end
  end
end

turtle.turnRight()
turtle.select(1)
turtle.craft()
turtle.turnRight()
turtle.drop()
turtle.turnLeft()

I just noticed that you have an argument in your craft() call. If I remember correctly, it doesn't need one. (EDIT: Guess it does. Someone should update the wiki to show this) I'm not updated to 1.4+ so I can't check right now. All I changed in the above code is removing the argument in craft() and adding an if statement that should stop the turtle from filling slot 6, which isn't required to create a furnace. Hope it works!
CastleMan2000 #6
Posted 29 September 2012 - 08:25 PM
Um, turtle.craft does need an argument. How many items you want to craft. The purpose of this program is to be modular, and basically craft anything you want. Also, ifs are not loops.
Anonomit #7
Posted 29 September 2012 - 08:31 PM
Um, turtle.craft does need an argument. How many items you want to craft. The purpose of this program is to be modular, and basically craft anything you want. Also, ifs are not loops.

Thanks! Again, I'm not updated to 1.4+ right now, so I'm just guessing here :)/>/>

So, what is it exactly that's wrong with your program? I'd love to help, but I'm not sure I understand your goal.
CastleMan2000 #8
Posted 29 September 2012 - 09:04 PM
The problem, well, here's an example.

Say I want to craft a wooden pickaxe. In the input chest I put:

PPP
XSX
XSX

P = Planks, S = Sticks, X = Nothing

The turtle puts this in to it's inventory:

PPP
SSX
XXX

That is the problem.
Doyle3694 #9
Posted 29 September 2012 - 09:06 PM
It'll put the stuff you suck in the currently selected slot as far as I'm concerned.
Anonomit #10
Posted 29 September 2012 - 09:10 PM
Ahh, well then the problem is that the turtle doesn't know what you're crafting. It takes the first item in the chest each time you use turtle.suck(), which is causing the weird organization.
Other than letting the turtle know what you're crafting, I would suggest putting strange items in the chest in place of nothing. If you use something that you would never use in a crafting recipe, like seeds, then you could have the turtle suck everything out, then compare every inventory slot to slot 16, where you would have seeds. If it matches, that slot goes back into the chest or a different chest. Your chest would look like this:

PPPXSXXSX

P = Planks, S = Sticks, X = Seeds

EDIT: It doesn't matter how things are arranged in the chest, as long as they're in the right order
Alex_Nikic9 #11
Posted 03 February 2013 - 01:25 AM
Well, if your using ComputerCraft 1.3, the turtle slots go like this:

123
456
789

and with 1.4:

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16