The problem i’m facing is that i’m making a game that contains the same concept as pong: having an element in common (in this case the tyles to break) that needs a class to be used.
I was thinking about initializing those “objects” with a for loop where i create a new class element for every cicle.
the only think is that when i do this i can’t use the methods of the class:
class Tyle(): def __init__(self, some_parameter): self.some_parameter = some_parameter def do_something(self): print(some_parameter) tyles = [] x = 1 for i in range(1, 4): tyles.append(Tyle, x) x += 1 for t in tyles: t.do_something() #here there is the problem
I tried giving a variable name to all the elements like this:
tyles = [] x = 1 for i in range(1, 4): a = Tyle(x) tyles.append(a) x += 1
But it doesn’t work either.
Is there a way to call class methods in this scenario?
Mighty_programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.