Using pygame.time.set_timer [SOLVED]

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
john hae
Regular
Posts: 50
Joined: Sun Sep 12, 2010 12:06 pm
Contact:

Using pygame.time.set_timer [SOLVED]

#1 Post by john hae »

Hello. I'm working on a screensaver via RenPy. I coded the following class for ending an interaction with a return code of "1" if mouse or keyboard activity is detected (that way I know that renpy.quit() should be immediately invoked to finish the app), or return code of "0" if the timer expired (that way I can move on to the next scene of the screensaver). However, can I use pygame.USEREVENT + 1 safely, or it's used internally by RenPy?

Thanks in advance.

Code: Select all

    import pygame

    class ILayer(renpy.Displayable):

        #############################################################
        def __init__(self, timerInterval=20000, **kwargs):
            renpy.Displayable.__init__(self, **kwargs)
            pygame.time.set_timer(pygame.USEREVENT + 1, timerInterval)

        def render(self, width, height, st, at):
            rv = renpy.Render(width, height)
            return rv

        #############################################################
        def event(self, ev, x, y, st):           
                 
            if ev.type == pygame.MOUSEBUTTONDOWN or ev.type == pygame.MOUSEMOTION or ev.type == pygame.KEYDOWN:
                pygame.time.set_timer(pygame.USEREVENT + 1, 0)
                return 1
            elif ev.type == pygame.USEREVENT + 1:
                pygame.time.set_timer(pygame.USEREVENT + 1, 0)
                return 0
            else:
                return
Last edited by john hae on Sat Nov 27, 2010 7:18 am, edited 1 time in total.
IKIGames. Follow us on Twitter: @superikigames.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Using pygame.time.set_timer

#2 Post by PyTom »

Quite a bit of the USEREVENT space is used internally by Ren'Py - I'm not sure there are any that are safe to use by user code. Instead of using pygame directly, you should use renpy.timeout, which schedules an event to be delivered after a while.

There's no guarantee as to what the event is, but you shouldn't need one - if it isn't an event you understand, you can just treat it as a timeout, after checking st to make sure that it's occured after your timeout.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

john hae
Regular
Posts: 50
Joined: Sun Sep 12, 2010 12:06 pm
Contact:

Re: Using pygame.time.set_timer [SOLVED]

#3 Post by john hae »

It worked perfectly. Thank you!
IKIGames. Follow us on Twitter: @superikigames.

Post Reply

Who is online

Users browsing this forum: Google [Bot]