Quick Time Event Trouble

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
renpyuseranon
Newbie
Posts: 11
Joined: Wed Dec 05, 2018 4:25 pm
Contact:

Quick Time Event Trouble

#1 Post by renpyuseranon »

I have a seven second video that I want to turn into a quick time event. The player needs to click during one of two points in the video to succeed, each point lasting for less than a second. If they click at any other point in the video, or don't click at all, they lose. How should I approach this? I found this code from another thread about implementing a QTE.

Code: Select all

screen timeout_event:
    key "a" action Jump("pressed_a")
    timer 5.0 action Jump("timed_out")

call screen timeout_event
Could I set up timers that represent the different intervals of the QTE (for example: a timer for the first 4 second failure period, a timer for the next .5 seconds success period, a timer for the next 2 second failure period, a timer for the last .5 seconds success period, and then a timer for the remainder that counts down to inevitable failure) and have it set up so clicking during one of these timers sends you to the corresponding win or fail state? If this would work, I have two additional questions: What would I use in place of

Code: Select all

key "a"
for the left mouse button, and how can I make it so that clicking the screen doesn't just skip the segment entirely like it normally would?

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Quick Time Event Trouble

#2 Post by rames44 »

Another approach might be to import the Python “time” module and record both when the video starts and then again when the user clicks, compute the difference and have logic from there. https://docs.python.org/2/library/time.html

This assumes that you don’t get significant delays between when the code thinks the video starts and when it actually starts playing that would skew the calculation.

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

Re: Quick Time Event Trouble

#3 Post by Alex »

Try something like this untested code (edited):

Code: Select all

screen timeout_event:
    modal True # player will be forsed to interact with screen
    key "rollback" action NullAction()
    key "rollforward" action NullAction()
    
    default click_on = False # some flag var

    key "mousedown_1" action If(click_on, [Hide("timeout_event"), Return()], [Hide("timeout_event"), Jump("lose")]) # left-click

    # timers will change the flag var
    timer 2.0 action SetScreenVariable("click_on", True)
    timer 3.0 action SetScreenVariable("click_on", False)
    timer 5.0 action SetScreenVariable("click_on", True)
    timer 6.0 action SetScreenVariable("click_on", False)
    timer 7.0 action [Hide("timeout_event"), Jump("lose")]


label start:
    scene black
    "..."
    show video_bg
    show screen timeout_event
    "click on 2-nd or 5-th second!"
    "You've did it!"
    "?"
    return

label lose:
    "Game over..."
    jump start
https://www.renpy.org/doc/html/screens.html
https://www.renpy.org/doc/html/screens.html#key
https://www.renpy.org/doc/html/keymap.html#keymap
http://www.pygame.org/docs/ref/key.html
https://www.renpy.org/doc/html/screen_actions.html
Last edited by Alex on Wed Dec 12, 2018 4:06 pm, edited 1 time in total.

renpyuseranon
Newbie
Posts: 11
Joined: Wed Dec 05, 2018 4:25 pm
Contact:

Re: Quick Time Event Trouble

#4 Post by renpyuseranon »

Wow, works perfect Alex. Didn't test it with a synced up video (obviously) but everything works exactly how I hoped. This "modal True" part will definitely come in handy for some other ideas I had too. Very much appreciated my man, and thank you rames44 for the help as well.

For people reading this in the future, replace this line from Alex's code:

Code: Select all

    timer 6.0 action [SetScreenVariable("click_on", False), [Hide("timeout_event"), Jump("lose")])
with the following:

Code: Select all

    timer 6.0 action SetScreenVariable("click_on", False), [Hide("timeout_event"), Jump("lose")]

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

Re: Quick Time Event Trouble

#5 Post by Alex »

renpyuseranon wrote: Wed Dec 12, 2018 4:00 pm...
I've edited the code a bit (there was warning that code is untested) :wink:

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], solarisdreams