Jump to content




getTargets() returns number?


  • You cannot reply to this topic
2 replies to this topic

#1 Spidercoder

  • New Members
  • 2 posts

Posted 21 July 2013 - 04:11 PM

I'm trying to learn how to use the sensor from OpenCCSensors.

According to this(http://www.computerc...e=OpenCCSensors) website getTargets() is supposed to return a string, but it doesn't.

Here's the code:
os.loadAPI("ocs/apis/sensor")
local sensor = peripheral.wrap("right")
local targets = sensor.getTargets()
for key, value in pairs(targets) do
print(key.." "..value)
end

When i run the program it says "Test:6: bad argument: Table expected, got number"
Why does getTargets() return a number?

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 21 July 2013 - 04:18 PM

Split into new topic.

You're supposed to use sensor.wrap instead of peripheral.wrap. Also, it returns a table when called correctly, not a string. :) And don't override the sensor variable.

#3 Spidercoder

  • New Members
  • 2 posts

Posted 21 July 2013 - 04:27 PM

Sorry, I meant to say a table, but was in a little hurry :)

But thanks alot. Can't believe i missed that, after about an hour of frustration :P
Thanks again!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users