Trying to make a QTE (possible infinite loop exception)

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
AlliyahtheDonut
Newbie
Posts: 5
Joined: Mon Sep 20, 2021 12:53 am
Contact:

Trying to make a QTE (possible infinite loop exception)

#1 Post by AlliyahtheDonut »

I'm currently trying to make a QTE that would let you mash a keyboard key to fill up a bar before a timer bar runs out, but the label game is pretty problematic, it always causes an infinite loop exception no matter how I restructure it T-T
Here's my code with comments below:

Code: Select all

transform alpha_dissolve:
    alpha 0.0
    linear 0.5 alpha 1.0
    on hide:
        linear 0.5 alpha 0 #this fades the bar

screen mash_meter:
    text "[mash_points]/[maxmash]" xalign 0.0 yalign 0.05
    bar value mash_points range maxmash xalign 0.0 yalign 0.1 xmaximum 200

screen buzz:
    if mash:
        key "w" action Jump("plus")

screen countdown(timer_jump, time=20):
    timer time repeat False action [ Hide('countdown'), Jump(timer_jump) ]
    bar value AnimatedValue(0, time, time, time) at alpha_dissolve

label start:
    $ mash = False
    $ mash_points = 0
    $ maxmash = 10
    "Game start! (Press \"w\" key)"

label game:
    while mash_points <= 10:
        show screen mash_meter
        show screen countdown("jump_fail")
        $ mash = True
        show screen buzz #this causes the exception in this current structure, I've changed up the code in this label many times
        if mash_points <= 11 and mash_points >= 9: #had to make it look like this since mash_points == 10 causes the exception too
            jump passed
        else:
            jump game

label plus:
    $ mash_points += 1
    jump game

label jump_fail:
    hide screen mash_meter
    hide screen countdown
    $ mash = False
    "Too slow!"
    jump start

label passed:
    hide screen buzz
    hide screen mash_meter
    hide screen countdown
    $ mash = False
    "You win!"
    return

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Trying to make a QTE (possible infinite loop exception)

#2 Post by hell_oh_world »

I'm currently trying to make a QTE that would let you mash a keyboard key to fill up a bar before a timer bar runs out

Code: Select all

screen qte(duration=10.0, goal=50):
  default value = 0
  hbox:
    bar value value range goal
    text "[value] / [goal]"
    
  key "keyup_K_SPACE" action [SetScreenVariable("value", value + 1), If(value >= goal, Return(True))]
  timer duration:
    action Return(value >= goal)

label start:
  call screen qte
  if _return:
    "Succeeded!!!"
  else:
    "Failed!!!"
Regarding your code, I"m not sure what's wrong there, but you should be calling some of your screens there not showing it. Showing it will just make it proceed instantly to the next statement, which makes the game run the next codes immediately. If you're planning to do some infinite loop make sure first that you pause the execution of your code before looping again to avoid infinite loop error.

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

Re: Trying to make a QTE (possible infinite loop exception)

#3 Post by Alex »

Also, check this sample - viewtopic.php?p=488400#p488400

AlliyahtheDonut
Newbie
Posts: 5
Joined: Mon Sep 20, 2021 12:53 am
Contact:

Re: Trying to make a QTE (possible infinite loop exception)

#4 Post by AlliyahtheDonut »

hell_oh_world wrote: Mon Sep 20, 2021 3:44 am
I'm currently trying to make a QTE that would let you mash a keyboard key to fill up a bar before a timer bar runs out

Code: Select all

screen qte(duration=10.0, goal=50):
  default value = 0
  hbox:
    bar value value range goal
    text "[value] / [goal]"
    
  key "keyup_K_SPACE" action [SetScreenVariable("value", value + 1), If(value >= goal, Return(True))]
  timer duration:
    action Return(value >= goal)

label start:
  call screen qte
  if _return:
    "Succeeded!!!"
  else:
    "Failed!!!"
Regarding your code, I"m not sure what's wrong there, but you should be calling some of your screens there not showing it. Showing it will just make it proceed instantly to the next statement, which makes the game run the next codes immediately. If you're planning to do some infinite loop make sure first that you pause the execution of your code before looping again to avoid infinite loop error.
slr I tried calling some of the screens, but the results are less-than-ideal XD
Your code is a whole lot simpler though (tysm OwO)
Does the timer go out in the same speed as AnimatedValue when set in the same number of seconds?

AlliyahtheDonut
Newbie
Posts: 5
Joined: Mon Sep 20, 2021 12:53 am
Contact:

Re: Trying to make a QTE (possible infinite loop exception)

#5 Post by AlliyahtheDonut »

Alex wrote: Mon Sep 20, 2021 2:19 pm Also, check this sample - viewtopic.php?p=488400#p488400
slr Hmm this looks interesting, thanks! :D

Post Reply

Who is online

Users browsing this forum: No registered users