0

estoy haciendo un pathfinding y al hacer la función de draw (para que se llene el tablero) me salta este traceback

Traceback (most recent call last):
  File "c:\Users\msi\Desktop\Phyton proyectos\Projects\Pathfinding.py", line 134, in <module>
    main(WIN, WIDTH)
  File "c:\Users\msi\Desktop\Phyton proyectos\Projects\Pathfinding.py", line 111, in main
    draw(win,grid, ROWS, width)
  File "c:\Users\msi\Desktop\Phyton proyectos\Projects\Pathfinding.py", line 87, in draw
    for row in grid:
TypeError: 'function' object is not iterable

Se que el error es claro, la función no es iterable, el problema es que sin esto, no hay manera de hacer el pygame.fill o win.fill, este es el código de la función

def draw(win, grid, rows, width):
    win.fill(WHITE)

    for row in grid:
        for node in row:
            node.draw(win)

    drawGrid(win, rows, width)
    pygame.display.update()

Tambien anteriormente he definido la funcion makeGrid para crear el grid, donde por primera vez menciono al node= Node()

def makeGrid(rows, width):
    grid = []
    gap = width // rows
    for i in range(rows):
        grid.append([])
        for j in range(rows):
            node = Node(i,j, gap, rows)
            grid[i].append(node)
    return makeGrid

¿Alguien tiene alguna idea de cual es la solución?

EDIT: Código de la clase

class Node:
    def __init__(self, row,col,width,rows_total):
        self.row = row
        self.col = col
        self.x = row * width
        self.y = col * width
        self.color = GREY
        self.neighbors = []
        self.width = width
        #self.height = height
        self.rows_total = rows_total

Código de la variable definida

def makeGrid(rows, width):
    grid = []
    gap = width // rows
    for i in range(rows):
        grid.append([])
        for j in range(rows):
            node = Node(i,j, gap, rows)
            grid[i].append(spot)
    return grid
12
  • return makeGrid retorna una función. ¿No debería retornar grid? No tiene sentido iterar llenando grid si luego vas a retornar otra cosa.
    – Candid Moe
    el 13 feb. 2021 a las 17:24
  • @CandidMoe Justo al momento de subir el código al stack miré mejor y me di cuenta de ese error, pero ahora retorna otro error. AttributeError: 'Node' object has no attribute 'draw' el 13 feb. 2021 a las 18:25
  • ¿Y qué es Node?
    – Candid Moe
    el 13 feb. 2021 a las 18:43
  • @CandidMoe perdona por no responder antes acabo de llegar a casa! el 13 feb. 2021 a las 21:04
  • @CandidMoe Node es la clase y node es la variable donde guardo la clase con i,j,gap y rows. Para poder iterarla. el 13 feb. 2021 a las 21:05

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.