Is it possible to make a minigame that when you press a key before the right time you lose?

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
lykoia
Newbie
Posts: 22
Joined: Tue Apr 14, 2020 11:15 am
Contact:

Is it possible to make a minigame that when you press a key before the right time you lose?

#1 Post by lykoia »

Hey all, newbie here

Is there some easy way to implement something like that in a game?

Thank you

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3786
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Is it possible to make a minigame that when you press a key before the right time you lose?

#2 Post by Imperf3kt »

Sure, this is can be really simple using renpy screen language (but it can get really complex depending on how you're using it)

All you need to do is create a screen, add a button, and assign an action to the button.
Then, add a timer, and make another action happen (or hide the screen, depends how your game will work and what the point of clicking the button is, etc)
Lastly, you simply show that screen within your game and voila.

To make it so a player loses if they click it too soon, you just need to have two different buttons, in the exact same spot. After a timer runs out, one button disappears and the correct button is all that's left.
There are, of course, other ways to achieve this as well, this is just one way, for example, another way is you could have just one button, clicking it will take you to a label, where a variable is checked. If you pressed the button too early, it has the default variable, and you fail. If you waited long enough, the timer set the variable to something else, and you pass instead.

Here's a really simple example: (untested)

Code: Select all

## declare and default the variable we use to check if a button was pressed too early
default myvar = False

## define some points for our game
default points = 0

## create a screen, add a button to it, and give it a timer (in this case, 1.5 seconds)
screen myScreen():
    textbutton _("CLICK HERE!!!") action Jump("fail_check")
    timer 1.5 action SetVariable("myvar", True)

label start:
    ## show the screen
    show screen myScreen
    "Click the button"

label fail_check:
    ## use python conditional
    if myvar:
        "You win!, you waited to press the button, yay!!!"
        jump win
    else:
        "Boo! You're impatient!"
        "You Lose"
        jump lose
        
label win:
    ## Use python to increment the value of "points" variable by 1
    $points + = 1
    ## Jump back to the beginning, to do the whole thing over
    jump start
    
label lose
    ## Show the player how many points they ended up with
    "You ended up scoring a total of [points] points"
    
    ## End the game
    return
Python conditionals:
https://www.w3schools.com/python/gloss_python_else.asp
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Draida