robotpy / pynetworktables

Pure python implementation of the FRC NetworkTables protocol
Other
60 stars 30 forks source link

problem running getDoubleArray #99

Closed KhanSimeoni closed 4 years ago

KhanSimeoni commented 4 years ago

Hello, I have been trying to use getDoubleArray, but I keep getting an error. I am using it in the following code:

table = NetworkTables.getTable("ML")

while 1:
    object1posX = table.getDoubleArray('boxes',0)

Unfortunatly, this returns the error:

AttributeError: 'NetworkTable' object has no attribute 'getDoubleArray'

Any idea what i'm doing wrong?

virtuald commented 4 years ago

Use getNumberArray instead.

KhanSimeoni commented 4 years ago

That returned the error

TypeError: 'int' object is not subscriptable
virtuald commented 4 years ago

What's the full stack trace?

KhanSimeoni commented 4 years ago

Is this what your looking for?

python3 test_network_receive.py 10.17.21.2
INFO:nt:NetworkTables initialized in client mode
DEBUG:nt.th:Started thread nt-dispatch-thread-0
DEBUG:nt.th:Started thread nt-client-thread-0
Traceback (most recent call last):
  File "test_network_receive.py", line 23, in <module>
    print("The center is at " + str((object1posX[3]-object1posX[1])+object1posX))
TypeError: 'int' object is not subscriptable
virtuald commented 4 years ago

The default value that you passed to getNumberArray is an integer, which is returned if the value isn't present in NetworkTables. Integers are not subscriptable, as the error message says.

Try getNumberArray('foo', [0,0,0,0]) instead. Or use None as the default, and check to see if the value is None and don't print if it is.

KhanSimeoni commented 4 years ago

Got an NameError: name 'getNumberArray' is not defined error


INFO:nt:NetworkTables initialized in client mode
DEBUG:nt.th:Started thread nt-dispatch-thread-0
DEBUG:nt.th:Started thread nt-client-thread-0
Traceback (most recent call last):
  File "test_network_receive.py", line 22, in <module>
    object1posX = getNumberArray('foo', [0,0,0,0])
NameError: name 'getNumberArray' is not defined
virtuald commented 4 years ago

... table.getNumberArray