Python Game Specific Data Error

I’m currently working on determining which switch is ours by using the getGameSpecificData() function. Every time I run it, I get an error telling me that it is outside of the range. My code for this is below.


# Determine is Switch is on the Right or Left
if (list(self.gameData)[0] == "L"):
    print("Left Switch")
elif (list(self.gameData)[0] == "R"):
    print("Right Switch")
else:
    # Report Error to Driver Station
    self.driverStation.reportError("Could Not Detect Switch Position! Quiting Auto Mode!")

Have you set the data on the DS? I’m not a python guy, but I suspect you would get that error if it returned an empty string.

Yeah, as Joe said, most likely you’re not setting the game data in the DS (or it hasn’t been transmitted yet). To prevent errors when this occurs, you should check to see if the game data is an empty string.

If the error occurs using the simulator or the unit tests, neither currently set the game specific data, and so it will be an empty string.

I’m curious as to why you’re casting the data to a list? Strings are accessible via index just like a list.

I originally was just accessing it the normal way, but I also tried it as a list; just for testing.

I was trying to run it through the unit tests, and that’s where my error sprung up. Is there a way to suppress it? Should I just force it to upload to the robot?

Sent from my iPhone using Tapatalk

For now, I would just check to see if the string is empty and if so set the variable you’re using to a valid value.

I’ll file a bug on pyfrc and we’ll get it fixed in the near future.