Jump to Different Label When Pressing Different Key

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
User avatar
Pink_Juicy
Regular
Posts: 26
Joined: Tue Feb 09, 2021 4:09 pm
Contact:

Jump to Different Label When Pressing Different Key

#1 Post by Pink_Juicy »

This is a bit difficult to explain, but I want to be able to make it jump to a different label (the fail screen) when you press any other key.

Code: Select all

screen qte():
    key ["h"] action Jump("qte_continue")
    else:
        action Jump("qte_fail")
I assumed maybe this would work, but I'm still learning new things about using screens in Ren'Py. I would really like a solution to this issue.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Jump to Different Label When Pressing Different Key

#2 Post by Imperf3kt »

the key 'h' is already in use for hiding the overlay.
Does this work for you if you use a different key?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

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

Re: Jump to Different Label When Pressing Different Key

#3 Post by Alex »

Pink_Juicy wrote: Sun Sep 10, 2023 8:21 pm ...
Try it like

Code: Select all

screen qte_1_scr(right_key, time_to_press, fail_label='', win_label=''):
    # just a mark for test purposes
    text "qte_1_scr is shown" align (0.5, 0.05)

    # to force player interact with the screen
    modal True

    # hide the screen and jump to fail_label after time is gone
    # (if fail_label is specified)
    if fail_label:
        timer time_to_press action [Hide('qte_1_scr'), Jump(fail_label) ]
    # or just hide the screen and process to next line of code
    else:
        timer time_to_press action [Hide('qte_1_scr'), Return()]

    # hide the screen and jump to win_label on right_key press
    # (if win_label is specified)
    if win_label:
        key right_key action [Hide('qte_1_scr'), Jump(win_label)]
    # or just hide the screen and process to next line of code
    else:
        key right_key action [Hide('qte_1_scr'), Return()]


screen qte_2_scr(right_key, time_to_press, fail_label='', win_label=''):
    text "qte_2_scr is shown" align (0.5, 0.05)

    modal True

    for key_ in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
        if key_ == right_key:
            if win_label:
                key right_key action [Hide('qte_2_scr'), Jump(win_label)]
            else:
                key right_key action [Hide('qte_2_scr'), Return()]
        else:
            if fail_label:
                key key_ action [Hide('qte_2_scr'), Jump(fail_label) ]
            else:
                key key_ action [Hide('qte_2_scr'), Return()]


label start:
    "..."
    show screen qte_1_scr(right_key='j', time_to_press=7.0, fail_label='fail_lbl', win_label='win_lbl')
    "Press j key (you have 7 sec.)..."

label fail_lbl:
    "x_x"
    jump start

label win_lbl:
    "Well done."
    show screen qte_1_scr(right_key='z', time_to_press=5.0, fail_label='fail_lbl') # win_label is not specified
    "Press z key (you have 5 sec.)..."
    "Well done #2."

    show screen qte_2_scr(right_key='L', time_to_press=7.0, fail_label='fail_lbl') # win_label is not specified
    "Press L (capital) key, the other key counts as fail, (you have 7 sec.)..."
    "Well done #3."

    show screen qte_2_scr(right_key='U', time_to_press=5.0, win_label='win_2_lbl') # fail_label is not specified
    "Press U (capital) key, the other key counts as fail, (you have 5 sec.)..."
    "You failed..."
    jump start

label win_2_lbl:
    "You win!"
    return
https://www.renpy.org/doc/html/screens. ... -statement
https://www.renpy.org/doc/html/screens.html#key
https://www.renpy.org/doc/html/screens.html#timer
https://www.renpy.org/doc/html/screen_actions.html#Hide
https://www.renpy.org/doc/html/screen_actions.html#Jump
https://www.renpy.org/doc/html/screen_a ... tml#Return

Post Reply

Who is online

Users browsing this forum: Bing [Bot]