Inactivity Timer in a RenPy Game

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.
Message
Author
User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Inactivity Timer in a RenPy Game

#16 Post by Alex »

initialzero wrote: Sat Jul 24, 2021 2:20 pm Unfortunately nothing happens while playing the game.
I put the code before label start.

Is there a better solution to solve it?
Could you provide the code you have so far?

initialzero
Regular
Posts: 27
Joined: Fri Jul 08, 2016 6:53 am
Contact:

Re: Inactivity Timer in a RenPy Game

#17 Post by initialzero »

PyTom wrote: Sat Jul 24, 2021 3:11 pm Here's my go at it, based on Alex's version.

Code: Select all

screen activity_timer():

    default warning = False

    timer 10.0 action SetScreenVariable("warning", True)
    timer 15.0 action MainMenu(confirm=False)

    if warning:
        text "Timeout in 5 seconds!"


label reset_timer:
    hide screen activity_timer
    show screen activity_timer
    return


label start:

    scene bg washington

    call reset_timer

    "First choice."

    call reset_timer

    "Hard mode - two choices, one timer."

    "And choice 2."

    call reset_timer

    "Part 3."

    return
In this version, calls to reset_timer reset the timer.

Note there's an accessibility issue here. While it might make sense to use this to reset a game in a demo setting, trying to increase game challenge with timers like this hurts people who might not speak the language the game is written in. (As well is people with cognitive disabilities, people with screaming children, etc.)
Thank you for your solution! It is possible to use the call reset_timer as a global timer for the whole game? It would be crazy to set for each line this call function.

initialzero
Regular
Posts: 27
Joined: Fri Jul 08, 2016 6:53 am
Contact:

Re: Inactivity Timer in a RenPy Game

#18 Post by initialzero »

Alex wrote: Sat Jul 24, 2021 3:12 pm
initialzero wrote: Sat Jul 24, 2021 2:20 pm Unfortunately nothing happens while playing the game.
I put the code before label start.

Is there a better solution to solve it?
Could you provide the code you have so far?

Code: Select all

# The game starts here.
screen main_menu_timer():
    timer 5.0 action MainMenu(confirm=False)
    key 'dismiss' action [Hide("main_menu_timer"), Show("main_menu_timer")]

label start:
    #image animation:
    #    "animation.jpg"
    #    0.5
    #    "animation2.jpg"
    #    0.5
    #    "animation3.jpg"
    #    repeat
    scene img6
    with fade
    #show animation
    play music "001.ogg" loop
    $ renpy.music.set_volume(1.0, 0, channel="music")


    
    # 0001 Welcome to Blabla  College!

    "With the soft breeze waving through his h"
    "Bla blabla can't help but smile to himself."
This is the start of the whole game.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Inactivity Timer in a RenPy Game

#19 Post by Alex »

initialzero wrote: Sat Jul 24, 2021 3:25 pm

Code: Select all

    key 'dismiss' action [Hide("main_menu_timer"), Show("main_menu_timer")]
Should be

Code: Select all

    key 'dismiss' action [Hide("main_menu_timer"), Show("main_menu_timer"), Return()]

initialzero
Regular
Posts: 27
Joined: Fri Jul 08, 2016 6:53 am
Contact:

Re: Inactivity Timer in a RenPy Game

#20 Post by initialzero »

Alex wrote: Sat Jul 24, 2021 3:37 pm
initialzero wrote: Sat Jul 24, 2021 3:25 pm

Code: Select all

    key 'dismiss' action [Hide("main_menu_timer"), Show("main_menu_timer")]
Should be

Code: Select all

    key 'dismiss' action [Hide("main_menu_timer"), Show("main_menu_timer"), Return()]
Thank you! Now it is running as it should be. The next bug is that the sound of clicking the start button will repeat after every bla bla lines in the game. I think there is a loop bug after using this code and it cant be solved.

Code: Select all

## Buttons #####################################################################
##
## These variables, along with the image files in gui/button, control aspects of
## how buttons are displayed.

define  gui.hover_sound = "gui/sfx/hover.ogg"
define  gui.activate_sound = "gui/sfx/select.ogg"
This sound hover.ogg is repeating

1. I could deactivate the sound
or
2. to reset the game and let the scripts start from the beginning like a rollback? Is there something like "action rollback" instead of "action mainmenu"?

https://www.renpy.org/doc/html/save_load_rollback.html

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]