Python Forum
Function Runs 10 Times Instead of Once
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function Runs 10 Times Instead of Once
#2
Your problem is in your when you hit 100 points you check_level()every frame and add 1 to the level each frame.

The way I can think to fix it is to have a variable for next_level and have it look to hit that. So when you get 100 points, you level up and then add 100 points to the next_level variable.

Something like this
def level_up()
  level += 1
  next_level += 100

if score >= next_level:
  level_up()

level_up() would be a good place to add a sound for level change too. Will make it more fun for you to test.
Reply


Messages In This Thread
RE: Function Runs 10 Times Instead of Once - by michael1789 - Feb-18-2020, 07:51 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020