Jump to content




OpenPeripheral chest monitor not working


2 replies to this topic

#1 Graypup

  • Members
  • 90 posts

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

#2 CometWolf

  • Members
  • 1,283 posts

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 by CometWolf, 25 January 2014 - 05:28 PM.


#3 Graypup

  • Members
  • 90 posts

Posted 27 January 2014 - 11:10 PM

View PostCometWolf, on 25 January 2014 - 05:13 PM, said:

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 by Graypup, 27 January 2014 - 11:11 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users