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

getTargets() returns number?

Started by Spidercoder, 21 July 2013 - 03:11 PM
Spidercoder #1
Posted 21 July 2013 - 05: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?
Lyqyd #2
Posted 21 July 2013 - 05: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.
Spidercoder #3
Posted 21 July 2013 - 05: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!