dimanche 9 octobre 2016

python nested if statements not working

I'm trying to make a game using pygame, and I've set up a couple of functions that I've tested and they work fine. However, in the code below, when I add a print statement to show if my code works, it prints on the first one but not the second. Any help?

for square in row:
    tile_x = row.index(square)
    # print statement works here
    if self.x_pos - tile_x >= -4 and self.x_pos - tile_x <= 4:
        tile_x = 4 - (self.x_pos - tile_x)
        tile_y = 4 - (self.y_pos - tile_y)
        if square == 'G':
            display('Grass',tile_x,tile_y)
            # print statement doesn't work here
        elif square == 'T':
            display('Tree',tile_x,tile_y)
        elif square == 'B':
            display('Bush',tile_x,tile_y)
        elif square == 'R':
            display('Rock',tile_x,tile_y)
        elif square == 'S':
            display('Stone',tile_x,tile_y)
        # display function has been tested, and it works fine

Aucun commentaire:

Enregistrer un commentaire