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

OpenPeripheral chest monitor not working

Started by Graypup, 25 January 2014 - 03:30 PM
Graypup #1
Posted 25 January 2014 - 04:30 PM
I have a program that is supposed to read the total amount of iridium in a chest, then phone home to my server, so I can check my UU progress anywhere.

Unfortunately, this throws an attempt to index nil error on line 7.

What am I doing wrong?

The setup is as follows: openperipheral installed, vanilla chest on the left of the computer.


p = peripheral
c = p.wrap("left")
while true do
  local totalUU = 0
  for i=1, 27 do
	local temp = c.getStackInSlot(i)
	if temp["qty"] ~= nil then --THIS IS LINE 7
	  totalUU = totalUU + temp["qty"]
	end
	temp = nil
  end
  --this is a demo thing and will 404, but we don't care!
  http.get("http://computercraft.info/update-uum.php?uum="..totalUU)
  print("told the server about my amazing "..totalUU.." iridium ore!")
  totalUU = 0
  sleep(180)
end

The serverside portion works FINE with manual requests
CometWolf #2
Posted 25 January 2014 - 05:13 PM
temp will be nil if there is no items in the slot it's checking. change line 7 to

if temp then --THIS IS LINE 7

Edited on 25 January 2014 - 04:28 PM
Graypup #3
Posted 27 January 2014 - 11:10 PM
temp will be nil if there is no items in the slot it's checking. change line 7 to

if temp then --THIS IS LINE 7

I didn't know lua did that… Looks like more code checks are in my future D:
Edited on 27 January 2014 - 10:11 PM