Jump to content




Openccsensor Table Issue


  • You cannot reply to this topic
1 reply to this topic

#1 Sjaelen

  • New Members
  • 1 posts

Posted 31 July 2013 - 04:14 PM

Hey all, I'm having a bit of an issue with openCCsensors and receiving results from the table. I have the following code:


os.loadAPI("ocs/apis/sensor")

local mon = peripheral.wrap("back")
local prox = sensor.wrap("top")
local targets = prox.getTargets()

term.redirect(mon)
term.clear()

while true do
term.setCursorPos(1,1)
for target in pairs(targets) do
  local info = prox.getTargetDetails(target)
  if info.Name == "Player" then
   print("Player: "..info.Username)
   print("( "..info.Position.X..", "..info.Position.Y..", "..info.Position.Z.. " )")
   print("-------------------------------------------------------------")
   sleep(0.5)
  end
end
end

It works fine until a player enters or leaves the area that the proximity sensor can detect, and then it returns an error "startup:14: attempt to index ? (a nil value)", which from what I understand is the code not being able to find the Name in the table that openCCsensors provides.

How would I go about fixing this so the code doesn't break when someone enters/leaves, and have it update to show the change?

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 31 July 2013 - 11:32 PM

Split into new topic.

Move the `local targets = prox.getTargets()` line to the beginning of the while loop, so that it will refresh the target list each time. Also, move the `sleep(0.5)` to just before the final end to have it sleep per iteration rather than per target.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users