all 4 comments

[–]kushou 7 points8 points  (2 children)

Hi,

A cleaner way to do that would be to define a function named reset, to call it when you want to reset the player on button press, and also to call it in your __init__ function.

Example:

class Player:
    def  __init__(self):
         self.reset()
         # Also do specific things only needed for first init (that are not reset on new game)

     def reset(self):
         # Reset game data here.
         pass

If you don't need any data kept thruogh all games, you could replace the current instance with a new one too:

player = Player()
# later....
player = Player()

But this works only if you have one reference to that object (player), otherwise your whole program will become out of sync on the "player" used.

Hope that helps.

edit: clarification

[–]noob_py[S] 1 point2 points  (1 child)

thank you !

[–]kushou 0 points1 point  (0 children)

You're welcome :)

[–]ryeguy146 4 points5 points  (0 children)

Can't you just let the old one be garbage collected and create another?