Page 1 of 1

Trying to make a QTE (possible infinite loop exception)

Posted: Mon Sep 20, 2021 1:32 am
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

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

Posted: Mon Sep 20, 2021 3:44 am
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.

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

Posted: Mon Sep 20, 2021 2:19 pm
by Alex
Also, check this sample - viewtopic.php?p=488400#p488400

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

Posted: Tue Sep 21, 2021 4:31 am
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?

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

Posted: Tue Sep 21, 2021 4:49 am
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