0

This is an example of my code

inv = peripheral.wrap("right")
var1 = inv.getAllStacks()
var2 = var1[1] --This should set var2 to another table
print(var2[1])

When I execute this program on an advanced computer with a diamond chest next to it, with things inside, it prints nothing at all. please help me out with this!

Domi
  • 51
  • 2
  • 5
  • What does that mean, "on an advanced computer with a diamond chest next to it"? Also, have you run it on a machine and gotten it to print stuff? what makes you think that `var2[1]` is not nil? – Oliver May 16 '14 at 03:23
  • Open Peripherals and computercraft (tags) are mods to the popular game "minecraft" which i was coding in. I am going to post an answer as I figured out what was wrong. – Domi May 21 '14 at 20:02

2 Answers2

0

Solved: What the getAllStacks() method does is returns a table full of dictionaries. So, to get the name of the item in stack one, you would do this:

chest = peripheral.wrap("right")
chestInv = chest.getAllStacks()
item1 = chestInv[1]
print(item1["name"]) --Because name is the term and the value is the name of the item.

this above code will print the name of the item in the first slot of chest.

Domi
  • 51
  • 2
  • 5
0

Use an addon (AddonCCPeripherals) and connect your chest with the Computer (with the proxy)! now you have to code:

chest = peripheral.wrap("diamond_0")
Diamond chest: "diamond_0"
Iron chest: "iron_0"

(sorry if there some Errors in my text, im from Germany [but the code is right])

Paulo MiraMor
  • 1,582
  • 12
  • 30
Guest
  • 1