Jump to content




How to get Item from specified Chest-slot?

turtle

  • You cannot reply to this topic
7 replies to this topic

#1 meigrafd

  • Members
  • 17 posts
  • LocationGermany

Posted 04 July 2015 - 08:35 PM

Hello everyone.
First: Sorry for my bad english :rolleyes:/>


Im currently trying to code an 'Automated Nuclear Reactor Control' Programm with a Computer and a Wireless Turtle beside the Reactor Champ... It works already very good - the Computer has a OpenCCsensor with a 'Inventory Sensor Card', scanning the Items every Second and compares them with a hardcoded Table.. If an Item is missed the Computer tells the Turtle to place a new of which Item into the Rector, and the Turtle have's 2 different Chests with รก Uran or Coolant Cells... This part works perfect.

But my Problem is now, that the Turtle also needs to replace "Depleted Uran" Cells - and heres my @topic Question:


Is it possible to tell the Turtle to select a specified Slot of another (not himselfs) Inventory?


I only know 'turtle.select()' but that is only for the Turtle-Inventory, not for an extern-Inventory :unsure:/>

The Computer knows the Slot-Number.. I also have a function on the Turtle for 'chestobj.getSizeInventory()' ... But all this is currently useless coz i dont know how to tell the turtle "suck slot#21 of Reactor-Inventory" :(/>


Is there maybe some trick? Or do i need to take all Item out and apply turtle.getItemDetail() on it? :wacko:/>


//EDIT: maybe helpful my Code:
Spoiler

Edited by meigrafd, 05 July 2015 - 01:26 PM.


#2 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 04 July 2015 - 11:48 PM

This topic is similar:
http://www.computerc...n-ftb-ultimate/


I believe OpenPeripherals adds a method to specify which slot to pull from, but I'm not sure.

#3 meigrafd

  • Members
  • 17 posts
  • LocationGermany

Posted 05 July 2015 - 06:57 AM

Thanx.

Seems like its possible, thats the Output: http://pastebin.com/Chyexhq8

But im confused how to use pullItem or pullItemIntoSlot or pushItemIntoSlot ? :blink:

//EDIT:

I've tryd:
reactor = peripheral.wrap("front")

reactor.pullItemIntoSlot(1,22,NORTH,2)  -- Output: Other inventory not found
reactor.pullItemIntoSlot(NORTH,22,1,2)  -- Output: Argument direction cannot be null
reactor.pullItemIntoSlot("north",22,1,2) -- Output: Other inventory not found

--same with reactor.pullItem()

reactor.listMethods() --[[ Output:
...
pullItem(direction,slot,maxAmount?,intoSlot?)
pullItemIntoSlot(direction,slot,maxAmount?,intoSlot?)
--]]
..i also tryd all other directions..

Edited by meigrafd, 05 July 2015 - 07:57 AM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 05 July 2015 - 07:33 AM

If it helps, remember that when you use a peripheral's function, the peripheral is what performs the action.

The description you got for pushItem could be re-written as:

Quote

pushItem(string direction, number source slot, number amount to push, number target slot)

Push an item from the current inventory into slot on the other one. Returns the amount of items moved.

So, let's say the inventory had 64 thingies in its third slot, you wanted it to push 32 of those to the turtle's tenth slot, and the turtle was to the south of the inventory. You might do:

local inventory = peripheral.wrap("front")
inventory.pushItem("south", 3, 32, 10)

You should be able to get more readable function descriptions (albeit only for OpenPeripheral-supported blocks) by typing this sort of thing into the command line:

openp/docs <peripheralSide> <functionName>


#5 meigrafd

  • Members
  • 17 posts
  • LocationGermany

Posted 05 July 2015 - 07:55 AM

Hm seems like im too stupid :(
I have setup on each direction a Chest with different Items in Slot1 and also another in Slot1-of-Turtle... Still doesnt work - still says "Other inventory not found" :angry:

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 05 July 2015 - 08:39 AM

The chest is telling you it can't find the turtle in the direction you're telling it to look. For example, if the chest is north of the turtle, then you must specify "south".

If that doesn't make sense, just use the opposite direction to whatever you've been doing.

#7 meigrafd

  • Members
  • 17 posts
  • LocationGermany

Posted 05 July 2015 - 08:52 AM

Ahh! Now i got it just befor you reply'd ;)

I thought the direction means "from the perspective of Turtle". :blink: :P

My Reactor is 'north' from Turtle, so i have to use inventory.pushItem("south",1,1,2)
'push' to get it from Chest to Turtle.
'pull' to get it from Turtle to Chest.

But what if i have more than 1 Chest? Actually it only works with one chest

Thats the current Test-Setup, but only the red-arrow markt Chest works with "west" -> http://s28.postimg.o...05_09_53_50.png

Or means 'inventory = peripheral.wrap("front")' that i only can use the 'front = west' direction? So i must setup all other Directions also with peripheral.wrap() ?

Edited by meigrafd, 05 July 2015 - 09:12 AM.


#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 05 July 2015 - 02:19 PM

When you wrap an inventory as a peripheral, you need to specify which side of the turtle faces the peripheral. This can be front/back/left/right/top/bottom (following the ComputerCraft standard for directions). You can't wrap peripheral blocks to the left/right if the turtle has tools in those positions. If the turtle turns/moves, you'll need to wrap the peripheral again.

When you tell a wrapped inventory peripheral to interact with another inventory, you instead use north/south/east/west/up/down (following the OpenPeripherals standard for directions).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users