0

finishing up the last game in the video tutorial I have been using to learn python/pygame coding.

When I ran the game, the following error is showing:

File "/home/dev/PycharmProjects/game7_meteor_game/game7_meteor_game.py", line 82, in GameInterface
    if player.cooling_time > 0:
UnboundLocalError: local variable 'player' referenced before assignment.

I have absolutely no idea at all what this means or how to correct it considering it is EXACTLY like the source code I got as part of the learning material.

Traceback:

Traceback (most recent call last):
  File "/home/dev/PycharmProjects/game7_meteor_game/game7_meteor_game.py", line 160, in <module>
    main()
  File "/home/dev/PycharmProjects/game7_meteor_game/game7_meteor_game.py", line 152, in main
    GameInterface(num_player=1, screen=screen)
  File "/home/dev/PycharmProjects/game7_meteor_game/game7_meteor_game.py", line 82, in GameInterface
    if player.cooling_time > 0:
UnboundLocalError: local variable 'player' referenced before assignment

My code:

   ---->if player.cooling_time > 0:
                player.cooling_time -= 1<------ 

        if (score_1 + score_2) < 500:
            background = bg_1
        elif (score_1 + score_2) < 1500:
            background = bg_2
        else:
            background = bg_3

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • can you show more code? – Prakash Dahal Aug 15 '21 at 07:19
  • I found the answer to this problem by going to reddit. Because I simply could not understand the "your question is almost exactly like these questions...." suggestions I asked there. A very helpful and patient person has since helped me locate the error in my coding. – Robo D Writah Aug 18 '21 at 05:18

0 Answers0