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

Routers and Turtles

Started by Epoch86, 28 December 2013 - 10:33 AM
Epoch86 #1
Posted 28 December 2013 - 11:33 AM
I'm setting up a Factorization Router/Barrel Sorting system and I'd like to have a turtle pull out any items that get "Stuck" in the router. I have little knowledge about LUA coding so I was gonna ask here for a program that would work. I need the turtle to basically scan the router, and if an item stays in the inventory for longer than 3 seconds to pull it out and place the item in a chest above the turtle. The placement needs to be like the picture below. Thanks in advance.
Buho #2
Posted 28 December 2013 - 12:30 PM
Search Google for Lua syntax or see the tutorials on this website and forum.

For specific turtle functions, search Google for "turtle api" which gets you this: http://computercraft.info/wiki/Turtle_%28API%29

Specifically, you'll probably want turtle.suckUp() to get stuff from the blue chest and turtle.dropDown() to place in the black chest. To wait three seconds, you'll want os.sleep(3).

That'll get you moving in the right direction. Happy coding!
Epoch86 #3
Posted 28 December 2013 - 01:53 PM
Thanks for the reply Buho. But how would i get the turtle to detect that there is an item in the router below it and, if there is an item, to wait 3 seconds before it sucks it out. So it would be like, detect item in inventory below, wait 3, suck item. And if the item gets pulled out before the timer is finished to reset.
Im using a turtle for a Factorization Router Sorting System and I need the turtle to pull out an item from the router if it gets jammed.
Edited on 28 December 2013 - 12:55 PM
Farrk #4
Posted 28 December 2013 - 03:14 PM
Thanks for the reply Buho. But how would i get the turtle to detect that there is an item in the router below it and, if there is an item, to wait 3 seconds before it sucks it out. So it would be like, detect item in inventory below, wait 3, suck item. And if the item gets pulled out before the timer is finished to reset.
Im using a turtle for a Factorization Router Sorting System and I need the turtle to pull out an item from the router if it gets jammed.

http://www.openperip...rization/router
Some methods have changed while going 1.6.4 but the one you are interested in is same: getStackInSlot()
If slot is empty it will return nil, otherwise will return the table with info about item(s) in that slot. Most likely item slot is 1 so you will have to call .getStackInSlot(1)
You will need to install OpenPeripherals if you don't have it installed already(most of FTB packs should have it in by default)


Also, in general people here avoid giving you ready programs to encourage you to learn lua :P/>

Actually I will add a function to detect if there is an item in slot in my topic later today(it's in my signature)
Edited on 28 December 2013 - 02:27 PM
Epoch86 #5
Posted 28 December 2013 - 08:22 PM
Thanks again Buho.

I've tried everything I can think of and nothing is working. I have tried going into the Interactive LUA in the turtles and when i do the peripheral wrap and try "getStackInSlot(1)" it comes up nil even when i have something in the inventory in slot 1. The way I'm typing it just to see if the command shows there is something in the router or not is like this

router.getStackInSlot(1)

I can get everything else to work later but I just need the turtle to look into the inventory of the router and see if there is an item in it.
Farrk #6
Posted 28 December 2013 - 08:39 PM

local router=peripheral.wrap("bottom")
if router.getStackInSlot(1)~= nil then
--do things if there is an item
end

If slot is empty it returns nil.

If that doesn't work then router slot for item is not 1. To determine number of slot that you look for you can place something inside(bear in mind that if router has no machine filter upgrade it will place it in turtle by default) and use code like


local router=peripheral.wrap("bottom")
local slotNum=1
while router.getStackInSlot(slotNum)== nil do -- should go through all slots until it finds one with an item
slotNum=slotNum+1
end
print(tostring(slotNum))
Edited on 28 December 2013 - 07:46 PM
Epoch86 #7
Posted 28 December 2013 - 09:14 PM
Wow that helped. But now that I have this:


local router=peripheral.wrap("bottom")
if router.getStackInSlot(1) = nil then
   sleep(3)
   turtle.suckDown()
   turtle.dropUp()
   end
if router.getStackInSlot(1) = 1 then
   sleep(.1)
   end
end

It gives me bios:339: [string "test"]:2: 'then' expected. what did I do wrong? and Thanks for helping.
wieselkatze #8
Posted 29 December 2013 - 08:04 AM
Should look like this:

local router=peripheral.wrap("bottom")
if router.getStackInSlot(1) == nil then
   sleep(3)
   turtle.suckDown()
   turtle.dropUp()
   end
if router.getStackInSlot(1) == 1 then
   sleep(.1)
   end
end

Just replace the = with ==
Epoch86 #9
Posted 29 December 2013 - 09:27 AM
Wait. I just tested it again and its working fine now. I was impatient and didn't wait long enough to let the sleep(3) go by. :P/> Thanks for the help. I'm learning slowly but surely.
Edited on 29 December 2013 - 08:30 AM
Epoch86 #10
Posted 29 December 2013 - 09:50 AM
And as impatient as I am I just noticed that the turtle is pulling the wrong things out of the router. When the supply of items to the router is too fast the items don't seem to leave the router and it makes the turtle think that its the same item. Causing the sleep(3) to keep going and it pulls out a stack of the item that isn't stuck in the router. Ugh, just one problem after another.
Edited on 29 December 2013 - 08:50 AM