Turtle: getAllStacks not in my version

  • 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

Niels Henriksen

New Member
Jul 29, 2019
502
0
1
I dont have getAllStacks on my server and Im not admin on the server so I cant just update it. Is there a way I can get info about content in chest?

I have tried this

Code:
for i = 0,(n-1) do
    local itemInfo = chest.getStackInSlot(i)
    if itemInfo ~= nil then
        logLine(itemInfo["name"])
        os.sleep(1)
    end
  end

but it fails with a diamondchest if there are not item in 100 slots.
 

Trunks9809

New Member
Jul 29, 2019
294
0
0
You need to wrap the chest as a peripheral:
Code:
local chest = peripheral.wrap("left")



Also, I'm not entire sure if it'll work on chests from IronChests. Maybe I just can't see the line on the OpenPeripherals site.
 

Niels Henriksen

New Member
Jul 29, 2019
502
0
1
You need to wrap the chest as a peripheral:
Code:
local chest = peripheral.wrap("left")

I already have that line in my script.

Also, I'm not entire sure if it'll work on chests from IronChests. Maybe I just can't see the line on the OpenPeripherals site.
It does. If I put an item in slot 100 then it can see all 108 slots in the chest.

Maybe I just have to rewrite my script so when it get a slot with no item it has to stop - and then wait until admin will update the server.
 

IndyDev13

Member
Jul 29, 2019
4
0
10
Maybe I just have to rewrite my script so when it get a slot with no item it has to stop - and then wait until admin will update the server.


That's pretty much what I do, I check both the slot it is in, and the next slot (just to be safe) if they are both nil, I then exit out of the loop. The reasoning for checking the one I am on and the next one is to just be 100% sure that the loop is at the end of the items and there wasn't a missing space in it.
 

apemanzilla

New Member
Jul 29, 2019
304
0
0
Try this, works whenever I use it:
Code:
local function getInventory( object )
  local data = {}
  for i=0, object.getSizeInventory() do
    data[i] = object.getStackInSlot(i)
  end
  return data
end
Just modify that to fit your needs.
 

Niels Henriksen

New Member
Jul 29, 2019
502
0
1
I have now tried to add Inventory Module to my turtle and I cant make it suck the item from the chest below :(
 

Bomb Bloke

New Member
Jul 29, 2019
612
0
0
Saying you "can't do something" is just a tad ambiguous. Makes it more then a bit difficult to tell you why.

What are you trying, and what is happening in response?

Is it any different running your code in an up-to-date SSP creative world?
 

Niels Henriksen

New Member
Jul 29, 2019
502
0
1
Saying you "can't do something" is just a tad ambiguous. Makes it more then a bit difficult to tell you why.

What are you trying, and what is happening in response?

I have a turtle with Inventory Module. Under the turtle is a chest with linking books.

I want to let the turtle suck a specific book up and insert it in a portal. Im using the command

p.suckUp(slotnumber, qty).

slotnumber is correct from the chest and qty is 1. But I get an "attemt to call nil" error.

p is correct because I can see the content of the chest on a monitor on another computer.

Im using Unleashed 1.1.3.
 

Bomb Bloke

New Member
Jul 29, 2019
612
0
0
You get "attempt to call nil" because the function isn't available to "p". This likely means you haven't wrapped the peripheral correctly. Odds are you're getting the side wrong - giving it a quick test, I find the basic inventory turtle has the module to its right.

You must specify the direction you're sucking from, not to. If the turtle is above the chest then you need p.suckDown.

Make sure the turtle's currently selected slot doesn't already contain items of another type or the operation will return false.
 

Niels Henriksen

New Member
Jul 29, 2019
502
0
1
Now I have tried this
Code:
local p = peripheral.wrap("right")
p.suckDown(1,2)

I have the turtle with the inventory module attached the the right side. The chest under. Slot 1 in chest contains item and slot 2 in turtle is empty.

Still same error :(

Its an wireless inventory turtle. And if I wrap("left") then I get no error. I dont get this...
 

Bomb Bloke

New Member
Jul 29, 2019
612
0
0
If you don't get an error when trying to suck, then you've got the wrapping sorted out. The command won't error out if you call it correctly but it's not possible to suck - then it just returns "false", so you can have your code detect that the operation was unsuccessful and respond accordingly.

p.suckDown(1,2) tries to take two items from the first slot in the chest, and place them into whatever slot the turtle has selected. You can change the turtle's selected slot with eg turtle.select(2). Again, that turtle slot must be empty before sucking (though odds are it'll work if whatever's in the chest's slot matches whatever's in the turtle's slot - but still, test with it empty to begin with). Odds are you'll also hit failure if the chest doesn't have at least two items in its first slot (or whatever quantity you try to pull out).