QTE Randomization

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
Skhizein
Newbie
Posts: 11
Joined: Fri May 03, 2013 12:29 pm
Contact:

QTE Randomization

#1 Post by Skhizein »

Currently I'm trying to put together a quick time event that involves randomizing what keys the player needs to press within a time limit. I'm completely new to this, so I'm sure I'm just overlooking some really simple syntax errors or something, but I can't get it to work.

This is what I have so far, combining pwisaguacate's code from this thread here with screens: http://lemmasoft.renai.us/forums/viewto ... =8&t=21136
(No doubt there's an easier way to accomplish this, but like I said I have no idea what I'm doing)

From my main script file:

Code: Select all

label roulette:
    $ test = renpy.random.randint(1, 4)
    $ survived = 0

    if test != 1:
        call screen timeout_event_a
    if test != 2:
        call screen timeout_event_w
    if test != 3:
        call screen timeout_event_s
    if test != 4:
        call screen timeout_event_d

label success:
    "You survived."
    $ survived += 1
    if survived == 5:
        "You survived 5 times."
        return
    else:
        jump roulette
    
label failure:
    "You failed."
    return
And from screens.rpy:

Code: Select all

screen timeout_event_a:
    frame:
        xpadding 10
        ypadding 10
        xalign 0.5
        yalign 0.5

        vbox:
            text "Press A!"
    key "a" action Jump("success")
    timer 3.0 action Jump("failure")
    
screen timeout_event_w:
    frame:
        xpadding 10
        ypadding 10
        xalign 0.5
        yalign 0.5

        vbox:
            text "Press W!"
    key "w" action Jump("success")
    timer 3.0 action Jump("failure")
    
screen timeout_event_s:
    frame:
        xpadding 10
        ypadding 10
        xalign 0.5
        yalign 0.5

        vbox:
            text "Press S!"
    key "s" action Jump("success")
    timer 3.0 action Jump("failure")
    
screen timeout_event_d:
    frame:
        xpadding 10
        ypadding 10
        xalign 0.5
        yalign 0.5

        vbox:
            text "Press D!"
    key "d" action Jump("success")
    timer 3.0 action Jump("failure")
No error messages have appeared, but the script only randomizes between timeout_event_a and timeout_event_w without ever hitting s or d. Also, the "survived" variable doesn't work; after 5 successes it just keeps going.

I'd really appreciate some help or input, if someone could point me in the right direction?

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: QTE Randomization

#2 Post by kankan »

The first problem- the one where you're only hitting two different screens- is because of how you're checking the random number. Say you randomly pull a 1. You'll skip the first if statement and take the second one because 1 != 2. Pull a 2, and you'll go down the first path....but this will also happen when you pull a 3 or 4, since none of them equal 1. So you have a 75% chance of taking the first if statement, a 25% chance of hitting the second, and no chance at hitting the other two. You probably want something more like

Code: Select all

if test == 1:
    call a's screen
elif test == 2:
    call b's
elif test == 3:
    call c's
else:
    call d's
For the second problem, I think what's happening is you're losing track of where you were before because you're using jump statements rather than call statements. I'm not very good at screen language, but I think after you jump from one of your key screens to the success label, that's the last label Ren'py remembers. As such, when you hit the "return" after a successful run, you'll just return back to that key screen. There's a more specific "return" action for screens; maybe using that might help? Personally I would do something more like the cookbook's Konami Code but it's probably needlessly complicated.

pwisaguacate
Veteran
Posts: 356
Joined: Mon Mar 11, 2013 11:03 pm
Contact:

Re: QTE Randomization

#3 Post by pwisaguacate »

$ survived = 0 has to be moved outside the label so the repeat upon a success won't reset the value to zero (fix made to the other thread to reflect this). Anyways, here's a working code that goes with the shortened screen code below it:

Code: Select all

label start:
    $ qte_key = None
    $ qte_key2 = None
    $ survived = 0
    "The girl, mistaking you for a goon, draws her handgun and fires!"

label qte_game:
    $ diceroll = renpy.random.randint(1, 4)

    if diceroll == 1:
        $ qte_key = "W"
        $ qte_key2 = "w"
    elif diceroll == 2:
        $ qte_key = "A"
        $ qte_key2 = "a"
    elif diceroll == 3:
        $ qte_key = "X"
        $ qte_key2 = "x"
    else:
        $ qte_key = "D"
        $ qte_key2 = "d"

    call screen quicktime_event

label success:
    "*BANG* I mean no harm! Stop shooting, please!"
    $ survived += 1
    if survived == 5:
        "You dodge each of five shots and escape."
        return
    else:
        jump qte_game

label failure:
    "*BANG* You lie in a puddle of blood with misogynistic angst."
The screen code can be shortened as below:

Code: Select all

screen quicktime_event:
    frame:
        xpadding 10
        ypadding 10
        xalign 0.5
        yalign 0.5

        vbox:
            text ("Press " + qte_key + "!")

    key qte_key2 action Jump("success")
    timer 2.0 action Jump("failure")
For the second problem, I think what's happening is you're losing track of where you were before because you're using jump statements rather than call statements
There's no call action for a screen, and it would cause issues if there is. In this case, hitting the key on time jumps out of the screen and prevents the failure from activating. It lost track of progress because $ survived = 0 was placed in the wrong place.

User avatar
Skhizein
Newbie
Posts: 11
Joined: Fri May 03, 2013 12:29 pm
Contact:

Re: QTE Randomization

#4 Post by Skhizein »

Thank you, SO MUCH, to both of you! That would have taken me forever to figure out on my own, if I ever did. It works like a charm now! Plus I understand the code a little bit more too, haha.

Post Reply

Who is online

Users browsing this forum: henne, Nozori_Games, Ocelot, snotwurm