I am kind of new to python and the concept of threading, so I have had some questions regarding it. I am trying to run a thread inside a class, but when I write the target with the "self.function()" form it doesnt work. If I leave the function without the "self." for example, "function()" then I get an error in the terminal telling me that I need to have the "self." in front of the function's name. Here is a simlified version of the code:
class pong:
def run_game(self):
while True:
self.bounce()
self.run_ball()
#There is more functions in this loop but it isnt important
#Then ive got another loop that i need to be running while the game is active:
def run_level():
while True;
self.level()
t1 = threading.Thread(self.run_game)
#This line of code up here is the problematic one. You see if I write it as it is it doesn't work, I get a self not defied error. If I write it like this ...Thread(run_game), then it looks for the self in front of the function name.
I really hope this will reach someone who knows about python very well and I whill get an answer. Thank you!
I tried threading as shown on the latter and it didn't work.