Quick question about Crafting Turtles

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

ndDean

New Member
Jul 29, 2019
38
0
0
So the one thing I have never really dipped into was ComputerCraft, but I figured I would need to do it sooner or later. I've been playing around with some code in the LUA interface on a crafty turtle to attempt to make a turtle autocraft oak wood into planks and then spit the planks into a separate chest. I have accomplished this somewhat, but there are two things I can't seem to get right.

#1. Is there a way to make the turtle.suckDown() function to only pull a specific amount from the inventory below it or am I stuck with it always pulling however many (up to a stack) that is in the next inventory spot of the chest. I tried using the turtle.dropDown() function to have it put back what I don't want it to use but since the wood it would be getting from the first chest is coming from a tree farm there is no way of knowing exactly how big the next stack it pulls is going to be if that makes sense. So I need to find a way to force the turtle to always grab 1 log at a time from the chest.

#2. Once I have all the code finished, how do I set this code to loop?

My current code is

turtle.suckDown() this currently grabs however many oak logs are in the next available inventory slot of the chest below it
turtle.dropDown(48) This only works if there is a full stack of logs, which is why I am having issue #1
turtle.craft() This turns them into the planks
turtle.dropUp() puts the planks into a chest above the turle


So how would I make that code^ loop over and over after starting it up.

Thanks in advance for any help you guys can provide, since I was unable to find any current help on this matter, I will be making a YouTube video later this week on how to do exactly this.
 

Adonis0

New Member
Jul 29, 2019
1,800
0
0
I believe for the suck down command, you can specify in the brackets how many items to pull (not 100% on this)

For the loop, you can use a while loop

The syntax is

while <condition to be true to activate loop> do
<code to be looped while the above condition is true>
end

So your code should be

While true do
turtle.suckDown(1)
turtle.craft()
turtle.place up()
end
 

ndDean

New Member
Jul 29, 2019
38
0
0
I believe for the suck down command, you can specify in the brackets how many items to pull (not 100% on this)

For the loop, you can use a while loop

The syntax is

while <condition to be true to activate loop> do
<code to be looped while the above condition is true>
end

So your code should be

While true do
turtle.suckDown(1)
turtle.craft()
turtle.place up()
end


Thanks so much for the loop command, however I tried specifying how many in the brackets, example: turtle.suckDown(16) and it still grabs however many there are in the next available inventory slot.

So, problem 2 is now solved, just godda figure out this first issue =D
 

connerity

New Member
Jul 29, 2019
12
0
0
If there is a specific number of logs you want to process, you can just do:

turtle.suckDown()
turtle.dropDown(turtle.getItemCount(1)-x)

Where 1 is the slot of the turtle's inventory where the logs will be, and x is the number of logs you want to process. This will keep x logs in the turtle's inventory.
 

vScourge

New Member
Jul 29, 2019
71
0
0
The regular turtle API doesn't support suckUp/suckDown with variable item counts, it's the whole stack in that slot or nothing. However, if you have the MiscPeripherals mod available it adds the Inventory Upgrade, which adds a second argument to its suckUp/suckDown, letting you specify the item count.
 

ndDean

New Member
Jul 29, 2019
38
0
0
If there is a specific number of logs you want to process, you can just do:

turtle.suckDown()
turtle.dropDown(turtle.getItemCount(1)-x)

Where 1 is the slot of the turtle's inventory where the logs will be, and x is the number of logs you want to process. This will keep x logs in the turtle's inventory.


Thanks to this I got it to function good enough for me.

My new code is

while true do
turtle.suckDown()
turtle.dropDown(turtle.getItemCount(1)-1) -- This is to make sure it only crafts one log at a time
turtle.craft()
turtle.dropUp()
end

The main reason I needed this code was because Unleashed doesn't have the autocrafting table anymore, so I had to come up with a solution for feeding planks into my boilers from a tree farm. This seems to have done the trick, hope this helps any others that might need it.

EDIT: I noticed that when there are no longer any logs in the chest below it to pull out it will come up with an error and stop the program, so I guess I will have to try something else. But we are getting closer!
 

TheLoneWolfling

New Member
Jul 29, 2019
260
-6
0
EDIT: I noticed that when there are no longer any logs in the chest below it to pull out it will come up with an error and stop the program, so I guess I will have to try something else. But we are getting closer!

The error is because it's trying to drop -1 logs into the chest below.

Try looping with sleep until there's at least 1 log.

Code:
while true do
  turtle.suckDown()
  while not turtle.getItemCount(1) do
    turtle.suckDown()
    os.sleep(1)
  end
  turtle.dropDown(turtle.getItemCount(1)-1) -- This is to make sure it only crafts one log at a time
  turtle.craft()
  turtle.dropUp()
end
 

ndDean

New Member
Jul 29, 2019
38
0
0
The error is because it's trying to drop -1 logs into the chest below.

Try looping with sleep until there's at least 1 log.

Code:
while true do
  turtle.suckDown()
  while not turtle.getItemCount(1) do
    turtle.suckDown()
    os.sleep(1)
  end
  turtle.dropDown(turtle.getItemCount(1)-1) -- This is to make sure it only crafts one log at a time
  turtle.craft()
  turtle.dropUp()
end

Just tried this, still end up with a "item count -1 out of range" message. It seems I need a way to make the turtle constantly scan for items in the chest and pull them out if any show up
 

sks0315

New Member
Jul 29, 2019
135
0
0
while true do
turtle.select(1)
do
turtle.suckDown()
os.sleep(0.1)
until turtle.getItemCount(1) > 0
turtke.dropDown(turtle.getItemCount(1) - 1)
turtle.select(13)
turtle.craft()
turtle.dropUp()
end

This should work....
 

ndDean

New Member
Jul 29, 2019
38
0
0
while true do
turtle.select(1)
do
turtle.suckDown()
os.sleep(0.1)
until turtle.getItemCount(1) > 0
turtke.dropDown(turtle.getItemCount(1) - 1)
turtle.select(13)
turtle.craft()
turtle.dropUp()
end

This should work....


bios:337 [string "test"]:6: 'end'
expected (to close 'do' at line 3)
 

Trunks9809

New Member
Jul 29, 2019
294
0
0
The main reason I needed this code was because Unleashed doesn't have the autocrafting table anymore, so I had to come up with a solution for feeding planks into my boilers from a tree farm. This seems to have done the trick, hope this helps any others that might need it.


Why not use the Sawmill or Cyclic Assembler from Thermal Expansion? Or the Liquicrafter from MFR? Or Applied Energistics autocrafting? There are a few ways of doing this that don't require CC code, if you'd prefer to avoid it.
 

connerity

New Member
Jul 29, 2019
12
0
0
while true do
while turtle.getItemCount(1)<1 do
turtle.suckDown()
end
turtle.dropDown(turtle.getItemCount(1)-1)
turtle.craft()
turtle.dropUp()
end

works, assuming your inventory with the logs is below the turtle and the inventory where the planks should go is above.
 

ndDean

New Member
Jul 29, 2019
38
0
0
Why not use the Sawmill or Cyclic Assembler from Thermal Expansion? Or the Liquicrafter from MFR? Or Applied Energistics autocrafting? There are a few ways of doing this that don't require CC code, if you'd prefer to avoid it.

I have never dabbled with ComputerCraft and I like to try out just about everything, so I could go a route I already know about. Or try something new =D