Python and json library - True vs true

Hi
can anyone help? Python uses ‘True’ but the json library uses ‘true’. The same for ‘False’ and ‘false’

Using the starter bot, ‘‘isOccupiedByCyberTruck’’ is defined as boolean, and returns ‘true’ or ‘false’ which is always interpreted by Python as ‘False’. Is there a way to convert the ‘true’ to “True”, or could the data type of ‘isOccupiedByCyberTruck’ be changed to text or something else?

>>> import json
>>> json.loads('{"test": true}')
{'test': True}

The python json library (which the starter bot uses) should convert the types correctly without any extra steps - are you using something else to parse the json state file?

Hi

I am using Windows 10 with Python 3.7.7. I am using the starterbot and have inserted the following line

def get_round_details(self) :

print('truck ',self.game_state[‘worldMap’][1][6][‘isOccupiedByCyberTruck’] )

When I run the bot from the command console,when I get to a round where I can see the Cybertruck on the map, I get a response
‘truck False’

I think that you might be confusing a cybertruck and a tweet object. The “T” on the map is the tweet powerup, which is the powerup that allows you to place cybertrucks (you can check if a block has a tweet on it by checking the surfaceObject of the block). Once a player places a cybertruck, the block’s isOccupiedByCyberTruck will turn true (and the block will show as a “C” on the map).

Hi

no. See the screen prints. You will see the output from the print instruction
print('truck ',self.game_state[‘worldMap’][1][6][‘isOccupiedByCyberTruck’] ) for each round

Thanks for clarifying - I think you have the wrong index, try print('truck ',self.game_state[‘worldMap’][0][5][‘isOccupiedByCyberTruck’] ) instead?

1 Like