#🔒 Hey I am trying to make a colision sistem between lists of objects, but it gives me an error

7 messages · Page 1 of 1 (latest)

lavish heath
#

Exception has occurred: AttributeError
type object 'Vida' has no attribute 'collidelist'
File "C:\Users\Davidpc\Desktop\Mi TR\Mi trabajo de recerca.py", line 26, in comer
if Vida.collidelist(Comida) >= 0:
^^^^^^^^^^^^^^^^
File "C:\Users\Davidpc\Desktop\Mi TR\Mi trabajo de recerca.py", line 91, in función_principal
Vida.comer(lista_vida, lista_comida)
File "C:\Users\Davidpc\Desktop\Mi TR\Mi trabajo de recerca.py", line 96, in <module>
función_principal()
AttributeError: type object 'Vida' has no attribute 'collidelist'

alpine houndBOT
#

@lavish heath

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

lavish heath
#
class Vida:
    def __init__(self, posición_x, posición_y, energía, velocidad, tie_vida, dirección, tamaño, vel_max, vel_min, tam_max, tam_min, generaciones):
        self.posición_x = posición_x
        self.posición_y = posición_y
        self.energía = energía
        self.velocidad = velocidad
        self.tie_vida = tie_vida
        self.dirección = dirección
        self.tamaño = tamaño
        self.vel_max = vel_max
        self.vel_min = vel_min
        self.tam_max = tam_max
        self.tam_min = tam_min
        self.generaciones = generaciones

    #esta función lo que hace es que cuando un objeto vida choque con un objeto comida, lo haga desaparecer y le de energía al objeto vida 
    def comer(lista_vida, lista_comida):
     for seres_vivos in lista_vida:
       if Vida.collidelist(Comida) >= 0:
        lista_comida.remove(Comida)
        seres_vivos.energia += 100
keen osprey
#

you try to access Vida.collidelist, but its not defined

lavish heath
#

so what should I do to make it detect whether an element from a list has colided with an element from another list?

alpine houndBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.