0

I'm just want to set a timer of 20 seconds in a function then jump to another:

Function 1:

example_gif = gif_pygame.load("giphy (1).gif")
def animatedgif():
    while True:
        example_gif.render(screen, (200 - example_gif.get_width() * 0.5, 150 - example_gif.get_height() * 0.5))
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit();
                sys.exit()
        crt_shader()

Function 2:

def first_question():

    while True:

        #screen.fill((255,255,255))
        render_text("Teste Teste",text_font,(255,255,255),0,0)   
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                quit()
        crt_shader()

I already tried threads ou multiprocess but i'm a quite beginner and the dont really understand how the explanations works.

The pygame.time.wait or time.wait won't working to. I'm looking to open a function after all, not waiting like a loading screen or something like the duplicates.

6
  • Yes, it works, but not for me. Read it again. The user wants to know other forms to do something that he already acchiev with this codes that i mention. Clearly the answears refers to other questions that nothing has to do with my question. Commented Nov 17, 2023 at 18:34
  • Please read How to create a Minimal, Reproducible Example and How do I ask a good question? Commented Nov 17, 2023 at 18:39
  • "Exit a function on a timer" is, in general, not a good design and you shouldn't be doing it in the first place. Look into state machines or event loops -- the way you're writing your program now it can't do more than one thing at a time, not even trivial things like responding to menu clicks. Once you follow good design practices this isn't a problem that you have. Commented Nov 18, 2023 at 4:02
  • That said, you can make your timeout show up as a pygame event, and return when you see that particular event. See the pygame.time module, as the duplicates already tell you to do; it shouldn't be a big leap to see return as a thing you can do when event.get() returns you a timer event scheduled with pygame.time.set_timer(). Commented Nov 18, 2023 at 4:04
  • (there are additional, worse ways to make a function exit on a timer, like sending a signal that throws an exception to the thread running a function, but they're Bad Ideas for a reason). Commented Nov 18, 2023 at 4:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.