I’m trying to get this method to show the shorthand of a given unit instead of just a space where a unit would be. I’ve modified it to the following so far:
"""Prints an ASCII version of the current game map for debug purposes"""
for y in range(28):
for x in range(28):
node = self.game_map[x][28 - y - 1]
if not node.blocked and not node.pathlength == -1:
location = [x, 28-y-1]
However, I get the following error which I can’t quite make sense of: TypeError: list indices must be integers or slices, not list
What is my problem here?
Also, when using the original definition, I get the following error: AttributeError: 'ShortestPathFinder' object has no attribute 'game_map'
Where is this one coming from? I don’t think that this error should occur in the original definition.
self.game_map.__getitem__(location) returns a list of units at that location (may be empty) instead of a single unit. This explains the TypeError, you are trying to call .shorthand on a list, not a unit like you thought. You will need to decide how you want to handle outputting this, but one option if you know the units are the same is just (this is only for displaying data):
units_at_loc = game_map[location, location]
if len(units_at_loc) > 0:
Regarding your second error, if you look at the ShortestPathFinder class you’ll notice that self.game_map is not created until navigate_multiple_endpoints is called. My guess would be you are trying to call print_map() before this function has been called, hence the AttributeError.
I would recommend making a new printing function or something since that print_map() is specific to the navigation class and displays data relevant to it. You could create a custom one in the GameState class (or anywhere you want really) that uses the game_map from there since you are displaying data relevant to that class.