Python Forum
[PyGame] Pygame, how to run an if statement only once, help!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Pygame, how to run an if statement only once, help!
#1
Hey guys.

I have been struggling with this problem for some time now, so i have to ask for help.
I got this game i am developing. You play as a spaceship, where your mission is to kill aliens, you get 1 point/score at each alien kill. I want to make a sound when you got a score of 10 only once. I got the score function working good and it is counting + 1 every time you kill an alien, but when the sound starts at 10 points it is playing that sound continually if i still got the score of 10. When i get 11 points it stops. I have tried with the pygame.mixer.stop after the yeah.play(), but then it isn't playing at all. Any suggestions?

My code look like this:

if score_value == 10:
yeah = pygame.mixer.Sound("PointsSound.wav")
yeah.set_volume(0.1)
yeah.play()
Reply


Messages In This Thread
Pygame, how to run an if statement only once, help! - by Kris1996 - Jan-28-2020, 04:32 PM

Forum Jump:

User Panel Messages

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