Python Forum

Full Version: program crashing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is a function that i made for showing all empty squares neighbouring a empty square when clicked. (the program is minesweeper)
def grannar():
    x = int(tomma[0])
    y = int(tomma[1])
    if x > 0 and y > 0:
        if grid[x-1][y-1] == 0:
            screen.blit(antal0, [int(((y-1) * grid_bredd)+11),int(((x-1) * grid_hojd)+69)])
            tomma.extend([(x-1),(y-1)])
                        
    if x > 0:
        if grid[x-1][y] == 0:
            screen.blit(antal0, [int((y * grid_bredd)+11),int(((x-1) * grid_hojd)+69)])
            tomma.extend([(x-1),(y)])
                       
    if x > 0 and y < 8:
        if grid[x-1][y+1] == 0:
            screen.blit(antal0, [int(((y+1) * grid_bredd)+11),int(((x-1) * grid_hojd)+69)])
            tomma.extend([(x-1),(y+1)])
                
    if y > 0:
        if grid[x][y-1] == 0:
            screen.blit(antal0, [int(((y-1) * grid_bredd)+11),int((x * grid_hojd)+69)])
            tomma.extend([x,(y-1)])
                         
    if y < 8:
        if grid[x][y+1] == 0:
            screen.blit(antal0, [int(((y+1) * grid_bredd)+11),int((x * grid_hojd)+69)])
            tomma.extend([x,(y+1)])
                         
    if y > 0 and x < 8:
        if grid[x+1][y-1] == 0:
            screen.blit(antal0, [int(((y-1) * grid_bredd)+11),int(((x+1) * grid_hojd)+69)])
            tomma.extend([(x+1),(y-1)])
                         
    if x < 8:
        if grid[x+1][y] == 0:
            screen.blit(antal0, [int((y * grid_bredd)+11),int(((x+1) * grid_hojd)+69)])
            tomma.extend([(x+1),y])
                         
    if y < 8 and x < 8:
        if grid[x+1][y+1] == 0:
            screen.blit(antal0, [int(((y+1) * grid_bredd)+11),int(((x+1) * grid_hojd)+69)])
            tomma.extend([(x+1),(y+1)])
    del tomma[0:2]
i then call this function like this:

tomma = []
            
            if grid[rad][kolumn] == 0:
                screen.blit(antal0, [int((kolumn * grid_bredd)+11),int((rad * grid_hojd)+69)])
                tomma.extend([rad,kolumn])

                while len(tomma) > 0:
                    grannar()
But when i run the program and click an empty square it crashes.
please post full unaltered error traceback (in error tags)
from initial view, looks like it might be an indentation issue