This page is out of date

You've reached a page on the Ren'Py wiki. Due to massive spam, the wiki hasn't been updated in over 5 years, and much of the information here is very out of date. We've kept it because some of it is of historic interest, but all the information relevant to modern versions of Ren'Py has been moved elsewhere.

Some places to look are:

Please do not create new links to this page.


Timed menus

This recipe lets you choose a certain (or secret) menu option automatically if you wait too long. These types of menus have been used in game series such as The Walking Dead and Sakura Taisen. It also includes a bar that notifies the player how much time they have left and can be customized with styles. The bar-type timer is recommended, since it makes the countdown easier to see, but there is also the option of using a numerical countdown.

First, create the timer screen and place it anywhere in your script.

transform alpha_dissolve:
    alpha 0.0
    linear 0.5 alpha 1.0
    on hide:
        linear 0.5 alpha 0
    # This is to fade the bar in and out, and is only required once in your script

screen countdown:
    timer 0.01 repeat True action If(time > 0, true=SetVariable('time', time - 0.01), false=[Hide('countdown'), Jump(timer_jump)])
    bar value time range timer_range xalign 0.5 yalign 0.9 xmaximum 300 at alpha_dissolve # This is the timer bar.

Then declare the variables the timer uses in your init block:

init:
    $ timer_range = 0
    $ timer_jump = 0

When you want to start the timer, declare these three variables, then show the countdown screen.

# time = the time the timer takes to count down to 0.
# timer_range = a number matching time (bar only)
# timer_jump = the label to jump to when time runs out

label menu1:
    $ time = 5
    $ timer_range = 5
    $ timer_jump = 'menu1_slow'
    show screen countdown
    menu:
        "Choice 1":
            hide screen countdown
            e "You chose 'Choice 1'"
            jump menu1_end
        "Choice 2":
            hide screen countdown
            e "You chose 'Choice 2'"
            jump menu1_end
   
label menu1_slow:
    e "You didn't choose anything."
    
label menu1_end:
    e "Anyway, let's do something else."


----
A more elaborate use of this is dynamic timed menus. This lets you change the menu entirely if the timer runs out. Like this:

label menu2:
    $ time = 5
    $ timer_range = 5
    $ timer_jump = 'menu2_v2'
    show screen countdown
    menu:
        "Choice 1 fast":
            hide screen countdown
            e "You chose 'Choice 1' fast"
            jump menu2_end
        "Choice 2 fast":
            hide screen countdown
            e "You chose 'Choice 2' fast"
            jump menu2_end

label menu2_v2:
    $ time = 5
    $ timer_range = 5
    $ timer_jump = 'menu2_slow'
    show screen countdown
    menu:
        "Choice 1 slow":
            hide screen countdown
            e "You chose 'Choice 1', but were slow"
            jump menu2_end
        "Choice 2":
            hide screen countdown
            e "You chose 'Choice 2', but were slow"
            jump menu2_end

label menu2_slow:
    e "You were really slow and didn't choose anything."
    
label menu2_end:
    e "Anyway, let's do something else."


----
If you're dead-set on replacing the bar with a big countdown number, you will need to modify the countdown screen like so:

screen countdown:
    timer 1 repeat True action If(time > 0, true=SetVariable('time', time - 1), false=[Hide('countdown'), Jump(timer_jump)])
    if time <= 2:
        text str(time) xpos .1 ypos .1 color "#FF0000" at alpha_dissolve
    else:
        text str(time) xpos .1 ypos .1 at alpha_dissolve

This makes the number count down every second - for example, 5, 4, 3, 2... When the countdown number is 2 or less, it turns red!