0

I am trying to make a score board in pygame.

score = 0 while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == MOUSEBUTTONDOWN: time.sleep(.2) screen.fill(w) score = score + 10 score1 = str(score) text = "Score : "+score1 myfont = pygame.font.SysFont("monospace", 15) label = myfont.render(text, 1, b) screen.blit(label, (10,10)) pygame.display.update() 

I don't want the player to be able to just hold down the mouse button down and the scoreboard keep counting. Is there anyway that I could do this? I am thinking of just for a first use game, counting how many clicks a person makes and then maybe calculate clicks per minute or something simple like that.

1
  • Why are you using time.sleep(2) in your script? Commented Mar 27, 2014 at 19:06

1 Answer 1

2

Firstly, your indentation is wrong. Your if event.type == MOUSEBUTTONDOWN: should be at the same level as if event.type == QUIT:.

Once you fix this, the code works as intended, since a MOUSEBUTTONDOWN event happens when you press the button. If you want to test if a button is down, you can get test it by calling pygame.mouse.get_pressed().

The problem might lay in the fact, that you are sleeping inside your event loop. This could lead to a freeze, since there might be more events to handle. If you want to reduce the frequency of the actions done by a click, you could create a timer, and check against that.

Sign up to request clarification or add additional context in comments.

1 Comment

I think my indentation got messed up when I copied and pasted it over, but thank you I will try to use this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.