1

In my code, I have a timer called timer. I started it somewhere in the game by doing timer.tick(). I was wondering if there is any kind of command that can stop the timer from recording time anymore and just stop. Because if I just set it to zero it keeps going, which I have tried. Is there a command like timer.stop(). I have tried many things such as looking online for this, and settings it to zero, etc..

Thank you EDIT_______________________

This is the variables before main loop

clock = pygame.time.Clock() FPS = 60 timer = pygame.time.Clock() storydelay = 5000 time_count = 0 

After main loop

if story: timer.tick() time_count += timer.get_time() if time_count < storydelay: mainmenu = False screen.blit(black_image,zero_position) if time_count > storydelay: mainmenu = True 

Basically what I want to do is when the time_count > storydelay, the timer should stop, so I can recall it back some other time

4
  • Well I just need one command but ok just a sec Commented May 30, 2016 at 22:42
  • Not sure what you mean by that? Commented May 30, 2016 at 22:45
  • So just set the timer = 0, and time_count = 0 after your last if statement. Commented May 30, 2016 at 23:07
  • Just in case you didn't see my comment below, you don't need the second pygame.time.Clock just use the clock instead of timer (but don't call clock.tick(FPS) twice). Commented Jun 2, 2016 at 19:51

1 Answer 1

2

Because timer.get_time() returns the time from the last call to timer.tick(), all you have to do is set the timer_count back to 0 and call timer.tick() to reset everything.

Here is an example:

import pygame clock = pygame.time.Clock() FPS = 60 timer = pygame.time.Clock() storydelay = 5000 time_count = 0 story = True timer.tick() while story: time_count += timer.tick() if time_count < storydelay: pass if time_count > storydelay: time_count = 0 print "story done" story = False clock.tick(FPS) main_menu = True timer.tick() while main_menu: time_count += timer.tick() if time_count > 3000: time_count = 0 print "menu done" main_menu = False clock.tick(FPS) print "done" 

As you can see, before each loop if started; timer.tick() is called and when each loop is closed time_count is reset

Hope this helps.

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

4 Comments

You don't need the second Clock.
True, I was debating whether to remove it or keep it in because it follows the OP's code a little more closely
Yeah, that comment was actually more directed @abc1234. Do OPs get notified about comments to answers?
Thank you very much

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.