Updated quick time event coding?

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
GlassHorse
Regular
Posts: 30
Joined: Mon Jan 08, 2018 12:14 am
Contact:

Updated quick time event coding?

#1 Post by GlassHorse »

Since most topics seem to be 3+ years old, I thought to ask in case there's a more current way to go about it.

I know some don't like quick time events, but they fit into my vn perfectly and I'm ok to take that chance. I'm looking to have it where it's a circle that has the key in it (or spacebar) and a larger circle closes in on it, and you have to press when the outer ring matches close to the outer part of the circle
(like the reverse of https://www.youtube.com/watch?v=9r6j3i1Su40&t=295s at the 5:00 mark) and where you have a certain amount of misses you can do before you loose.

I feel this can be done in a bar like timer, but hiding the bar and having this as a transparent animation.

There's also at the end of this a jojo like animation with you pressing certain keys (or spacebar) to have one punch animation appear and then another in an extremely fast fashion, where you would need to press enough to "defeat" the character without anything going at you, but your bar depletes a bit when you stop clicking fast enough. (I know this would probably have to do with some timer where every second 1 point is taken off no matter what and you have to get to like fifty).

If anyone can help with these I would be beyond excited.

take care,
Pat B.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Updated quick time event coding?

#2 Post by _ticlock_ »

Hi, GlassHorse,

You can do a simple qte event with screen language using a timer, key, and ATL for the displayable.

I modify one of my files to fit your example(I used squares for demonstration). Try this:

Code: Select all

default key_text = {
    'K_LEFT': "\u2190",
    'K_UP': "\u2191",
    'K_RIGHT': "\u2192",
    'K_DOWN': "\u2193"
    }

transform zoom_out(time_out):
    zoom 1.0
    linear time_out zoom 0.25

screen qte(qte_key, time_out, x,y):
    timer time_out action Return(False)
    key qte_key action Return(True)

    text _("Score = [score]") xalign 0.5 yalign 0.0

    #Displayable with transform
    add Solid("#fa5", xysize=(200,200)):
        xpos x ypos y
        xanchor 0.5 yanchor 0.5
        at zoom_out(time_out)
    add Solid("#800", xysize=(50,50)):
        xpos x ypos y
        xanchor 0.5 yanchor 0.5
    add Text(key_text[qte_key], size=40, bold = True):
        xpos x ypos y
        xanchor 0.5 yanchor 0.5

label qte_game(n):
    $ score = 0
    $ i = 0
label .cycle:
    if i < n:
        python:
            qte_key = ['K_LEFT','K_RIGHT','K_UP','K_DOWN'][renpy.random.randint(0,3)]
            qte_x = renpy.random.random()
            qte_y = renpy.random.random()
            qte_time_out = 1

        call screen qte(qte_key,qte_time_out,qte_x,qte_y)
        if _return:
            $ score += 1
        $ i += 1
        jump .cycle
    "Total score is [score]"
    return
You call label qte_game with parameter that defines how many qte you need:

Code: Select all

label start:
    call qte_game(10)

GlassHorse
Regular
Posts: 30
Joined: Mon Jan 08, 2018 12:14 am
Contact:

Re: Updated quick time event coding?

#3 Post by GlassHorse »

Thank you. I will give it a go :)

GlassHorse
Regular
Posts: 30
Joined: Mon Jan 08, 2018 12:14 am
Contact:

Re: Updated quick time event coding?

#4 Post by GlassHorse »

So, I'm getting things going with the boxes, but how do I know what arrow key goes with which box?

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Updated quick time event coding?

#5 Post by _ticlock_ »

Do you see arrow symbols inside the inner box?
Change the dictionary values to text instead just to check that the problem with unicode symbols:

Code: Select all

default key_text = {
    'K_LEFT': "Left",
    'K_UP': "Up",
    'K_RIGHT': "Right",
    'K_DOWN': "Down"
    }
If it works it is probably your editor uses different encoding.

PS: you can use images instead:

Code: Select all

default key_text = {
    'K_LEFT': "Left.png",
    'K_UP': "Up.png",
    'K_RIGHT': "Right.png",
    'K_DOWN': "Down.png"
    }
But then change this lines:

Code: Select all

    add Text(key_text[qte_key], size=40, bold = True):
        xpos x ypos y
        xanchor 0.5 yanchor 0.5
To this:

Code: Select all

    add key_text[qte_key]:
        xpos x ypos y
        xanchor 0.5 yanchor 0.5

GlassHorse
Regular
Posts: 30
Joined: Mon Jan 08, 2018 12:14 am
Contact:

Re: Updated quick time event coding?

#6 Post by GlassHorse »

Alright went a little over the top in my process. First defined the images just to be extra safe before the start label

Code: Select all

image i_left = ("i_left.png")
image i_up = ("i_up.png")
image i_right = ("i_right.png")
image i_down = ("i_down.png")
------------------------
I think my problem is the label start. I renamed it QuicktimeEvent, just because I already have a start at the beginning (sounds repetitive haha). I also changed the "n" to a "q," because one of my character's is defined by n and I just don't want them to get mixed up somehow
So here's what I have (I'm beyond grateful by the way)

Code: Select all

default key_text = {
    'K_LEFT': "i_left",
    'K_UP': "i_up",
    'K_RIGHT': "i_right",
    'K_DOWN': "i_down"
    }

label QuicktimeEvent:
    call qte_game(10)

transform zoom_out(time_out):
    zoom 1.0
    linear time_out zoom 0.25

screen qte(qte_key, time_out, x,y):
    timer time_out action Return(False)
    key qte_key action Return(True)

    text _("Score = [score]") xalign 0.5 yalign 0.0

    #Displayable with transform
    add Solid("#fa5", xysize=(200,200)):
        xpos x ypos y
        xanchor 0.5 yanchor 0.5
        at zoom_out(time_out)
    add Solid("#800", xysize=(50,50)):
        xpos x ypos y
        xanchor 0.5 yanchor 0.5
    add key_text[qte_key]:
        xpos x ypos y
        xanchor 0.5 yanchor 0.5

label qte_game(q):
    $ score = 0
    $ i = 0
label .cycle:
    if i < q:
        python:
            qte_key = ['K_LEFT','K_RIGHT','K_UP','K_DOWN'][renpy.random.randint(0,3)]
            qte_x = renpy.random.random()
            qte_y = renpy.random.random()
            qte_time_out = 1

        call screen qte(qte_key,qte_time_out,qte_x,qte_y)
        if _return:
            $ score += 1
        $ i += 1
        jump .cycle
    "Total score is [score]"
    return

------------------------------------------------

It works and doesn't stop the game with an error, but it will say image ' ' not found
(don't worry, I'm not making a DDLC fan vn, they're just placeholders so I just don't have solid blocks of color like my first project's placeholders)

I also attached the image folder to show that the images are in.
Attachments
folder.png
image.png

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Updated quick time event coding?

#7 Post by _ticlock_ »

Strange. I don't see right now what can be the reason. Is it possible that you have the variables i_left and others defined somewhere else? It tries to find image "" for some reason. If you directly add the displayable do you see the image:

Code: Select all

    #add key_text[qte_key]:
    #    xpos x ypos y
    #    xanchor 0.5 yanchor 0.5

    add "i_left":
        xpos x ypos y
        xanchor 0.5 yanchor 0.5

GlassHorse
Regular
Posts: 30
Joined: Mon Jan 08, 2018 12:14 am
Contact:

Re: Updated quick time event coding?

#8 Post by GlassHorse »

Ok, so I got it to work when I took out all of the code except
- defining the images (arrows, backgrounds, character)
- defining the name/type/color of text

Code: Select all

#TEXT OF CHARACTER
define n = Character("Natsuki", color="#fa87e9", what_font="DotGothic16-Regular.ttf", what_color="#ab2797")

#IMAGES (CHARACTERS/BG/ASSETS/ETC.)
image BG_Outside = ("BG_Outside.png")
image I_Natsuki = ("I_Natsuki.png")
image I_NatsukiOpen = ("I_NatsukiOpen.png")

#IMAGES OF ARROWS
image i_left = ("i_left.png")
image i_up = ("i_up.png")
image i_right = ("i_right.png")
image i_down = ("i_down.png")

#TEST AREA

label start:

label classroom:

    scene BG_Outside
    show I_Natsuki

    n "Looks like the call function worked on both love/hate fruit"

    n "Nice"

    n "We're going to try something that will make of break this game now"

    n "Quick time events!"

    n "This is where you have to press a button, click your mouse, or click
    an area on your screen at the right time"

    n "Going to start with something super simple"

    n "A spacebar image and you press the s key to win"

    n "Here we go"

default key_text = {
    'K_LEFT': "i_left",
    'K_UP': "i_up",
    'K_RIGHT': "i_right",
    'K_DOWN': "i_down"
    }

label QuicktimeEvent:
    call qte_game(10)

transform zoom_out(time_out):
    zoom 1.0
    linear time_out zoom 0.25

screen qte(qte_key, time_out, x,y):
    timer time_out action Return(False)
    key qte_key action Return(True)

    text _("Score = [score]") xalign 0.5 yalign 0.0

    #Displayable with transform
    add Solid("#fa5", xysize=(200,200)):
        xpos x ypos y
        xanchor 0.5 yanchor 0.5
        at zoom_out(time_out)
    add Solid("#800", xysize=(50,50)):
        xpos x ypos y
        xanchor 0.5 yanchor 0.5
    add key_text[qte_key]:
        xpos x ypos y
        xanchor 0.5 yanchor 0.5

label qte_game(q):
    $ score = 0
    $ i = 0
label .cycle:
    if i < q:
        python:
            qte_key = ['K_LEFT','K_RIGHT','K_UP','K_DOWN'][renpy.random.randint(0,3)]
            qte_x = renpy.random.random()
            qte_y = renpy.random.random()
            qte_time_out = 1

        call screen qte(qte_key,qte_time_out,qte_x,qte_y)
        if _return:
            $ score += 1
        $ i += 1
        jump .cycle
    "Total score is [score]"
    return
The only I can think of that is different is that the original vn called on variables right after the start label

Code: Select all

label start:

    call variables

    jump classroom


label classroom:
(I probably don't need the "jump" in that one and just let it flow from start to label classroom)

And at the end of all of the code in the vn was

Code: Select all

label variables:


    #First Test section
    $ firstStart = True

    $ YuriAppeared = False

    $ PlayerMoney = 0
I'm guessing it has something to do with that? I also have a separate script just for screens. Those are the only things I see that could of been an issue. I'm new to setting variables (boolean n' such)

Let me know what you think. Beyond grateful

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Updated quick time event coding?

#9 Post by _ticlock_ »

GlassHorse wrote: Sat Mar 20, 2021 9:21 pm The only I can think of that is different is that the original vn called on variables right after the start label
This should not cause the problem. I think the interference is somewhere else. My guess was that you defined variables with the same name somewhere else (key_text, i_left, etc). Potentially it could be a bug during compilation. That should be solved by "Force Recompile" from the launcher.

BTW:
1) You don't really need brackets when defining images:

Code: Select all

image i_left = "i_left.png"

2) In modern RenPy it is recommended to "define" variable with default statements and constants with define statements. (This can help to avoid possible problems with save files between different versions of the game.). For example, instead of using "label variables", use default statements (outside of label and outside of init blocks):

Code: Select all

default firstStart = True
default YuriAppeared = False
default PlayerMoney = 0

default score = 0
default i = 0
Assuming that label qte_game will be called multiple times you still need to set the values to zero values:

Code: Select all

label qte_game(q):
    $ score = 0
    $ i = 0
label .cycle:
    ...

GlassHorse
Regular
Posts: 30
Joined: Mon Jan 08, 2018 12:14 am
Contact:

Re: Updated quick time event coding?

#10 Post by GlassHorse »

Thank you (sorry for the pause) :) I will try this

Post Reply

Who is online

Users browsing this forum: Google [Bot]