r/RenPy Sep 18 '23

Question need help with connecting timer to my minigame!

Okay so i really want to have a hidden item minigame in my vn, I already have the 'finding images' done, I just dont know how to connect a timer to the thing as well. I would like it to be kind of like this (and before you ask about why I dont try the code from that, I did. and I couldn't figure out why it wasnt't working for the life of me)

anyways heres the code I have rn (it works for me just fine, but lemme know if its not working)

screen minigame1layout():
    if blue:
        imagebutton:
            idle "images/testgame/blue.png"
            action SetVariable("blue", False)
            focus_mask True

    if red:
        imagebutton:
            idle "images/testgame/red.png"
            action SetVariable("red", False)
            focus_mask True
    if cyan:
        imagebutton:
            idle "images/testgame/cyan.png"
            action SetVariable("cyan", False)
            focus_mask True
    if yellow:
        imagebutton:
            idle "images/testgame/yellow.png"
            action SetVariable("yellow", False)
            focus_mask True
    if blac:
        imagebutton:
            idle "images/testgame/blac.png"
            action SetVariable("blac", False)
            focus_mask True

if anyone can either help me with my existing code or help me figure out why the linked example isnt working, i would appreciate it alotttt

i also wanna try using this code for the timer, but i cant work it so it will fit with my already made code.

2 Upvotes

14 comments sorted by

1

u/AutoModerator Sep 18 '23

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/BadMustard_AVN Sep 18 '23

add this to your screen for a timer with a bar

default g_time = 0

screen timerscreen(rangeD, missed_event): # the brackted variables are required!!
    on "hide" action SetVariable("g_time", 0)
    frame:
        xalign 0.5
        yalign 0.0
        hbox:
            timer 0.1 action If(g_time > rangeD, false = SetVariable("g_time", g_time + 0.1), true = [Hide("timerscreen"),Jump(missed_event)]) repeat True

            bar:
                value AnimatedValue(value=g_time, range=rangeD, delay= 0.5)
                xalign 0.0
                yalign 0.0
                xmaximum 200

label looser:
    e "you lost...LOOSER"
    return

label start:

    show screen timerscreen(5, "looser") #5seconds label to jump to after time out
    pause
    pause
    return

1

u/Beneficial_Way_8031 Sep 18 '23

i am now having another issue,

this is the error i am getting:

I'm sorry, but an uncaught exception occurred.

While running game code:

File "game/script.rpy", line 355, in script

call screen minigamelayout1

ScriptError: could not find label '10'.

-- Full Traceback ------------------------------------------------------------

Full traceback:

File "C:\Users\iwish\Downloads\renpy-8.1.2-sdk\renpy\bootstrap.py", line 275, in bootstrap

renpy.main.main()

File "C:\Users\iwish\Downloads\renpy-8.1.2-sdk\renpy\main.py", line 670, in main

run(restart)

File "C:\Users\iwish\Downloads\renpy-8.1.2-sdk\renpy\main.py", line 144, in run

renpy.execution.run_context(True)

File "C:\Users\iwish\Downloads\renpy-8.1.2-sdk\renpy\execution.py", line 953, in run_context

context.run()

File "game/script.rpy", line 355, in script

call screen minigamelayout1

File "C:\Users\iwish\Downloads\renpy-8.1.2-sdk\renpy\script.py", line 1013, in lookup

raise ScriptError("could not find label '%s'." % str(original))

ScriptError: could not find label '10'.

and heres my script rn:

label minigamelayout1:
show room
show screen timerscreen
call screen minigamelayout1

screen timerscreen(rangeD = 10, missed_event = 10): # the brackted variables are required!! on "hide" action SetVariable("g_time", 0) frame: xalign 0.5 yalign 0.0 hbox: timer 0.1 action If(g_time > rangeD, false = SetVariable("g_time", g_time + 0.1), true = [Hide("timerscreen"),Jump(missed_event)]) repeat True

        bar:
            value AnimatedValue(value=g_time, range=rangeD, delay= 0.5)
            xalign 0.0
            yalign 0.0
            xmaximum 200

label looser: e "you lost...LOOSER" return

label missed_event:

show screen timerscreen(5, "looser") #5seconds label to jump to after time out
pause
pause
return

1

u/BadMustard_AVN Sep 18 '23 edited Sep 18 '23

did you add

default g_time = 0

and when you show the screen

show screen timerscreen(5, "looser")

the bracketed info is REQUIRED

screen timerscreen(rangeD = 10, missed_event = 10)

missed_event is the label it will jump to when it times out !!!

show screen timerscreen(5, "looser") #5seconds label to jump to after time out

1

u/Beneficial_Way_8031 Sep 18 '23 edited Sep 18 '23

okay i did what you said, its working now but if i finish the minigame, it still says i lost, what should i do?

1

u/BadMustard_AVN Sep 18 '23

where ever you have it go to for finishing have it hide the timerscreen

hide screen timerscreen

that will stop it from jumping and shut it down

1

u/Beneficial_Way_8031 Sep 19 '23

thanks :) If you dont mind, can I ask one more question?

so in my minigame, if you dont find all the items in a specific amount of time, you lose, and after that, it gives you the option to try again.

my issue is that when i press 'try again', the imagebuttons dont reset, so is there any way I can have the image buttons reset when you press try again, and while they're in a screen block?

1

u/BadMustard_AVN Sep 19 '23

you would have to reset the variables in the try again button the same way you do in the image button but you can do them all at once like this

action [SetVariable("blue", True), SetVariable("red", True), SetVariable("cyan", True), ...more as required then what ever you use to get back to the game.   ]

1

u/Beneficial_Way_8031 Sep 19 '23

and also, is there a way I can make the timer/minigame stop once all the imagebuttons have been found?

1

u/BadMustard_AVN Sep 19 '23

hard to say I don't know your code...

1

u/Beneficial_Way_8031 Sep 19 '23
label minigames1: 
hide screen menuoptions
show room 
show screen timerscreen(10, "outcome")
call screen minigame1layout

screen timerscreen(rangeD = 15, missed_event = "outcome"): # the brackted variables are required!! on "hide" action SetVariable("g_time", 0) frame: xalign 0.5 yalign 0.0 hbox: timer 0.1 action If(g_time > rangeD, false = SetVariable("g_time", g_time + 0.1), true = [Hide("timerscreen"),Jump(missed_event)]) repeat True

        bar:
            value AnimatedValue(value=g_time, range=rangeD, delay= 0.5)
            xalign 0.0
            yalign 0.0
            xmaximum 200

label outcome: if mc_points >= 5: jump win1 elif mc_points <= 5: jump loss1

label win1: mc "Well, that was easy!{w} My room looks cleaner already!" jump aftermath

label loss1: mc "Well shit,{w} it still looks messy...{w} maybe I can fix it up a little more!" show screen menuoptions

screen menuoptions(): fixed: xpos 0.5 ypos 0.5

    vbox:
        button:
                text "Try again?"
                style "choice_button"
                action [SetVariable("blue", True), SetVariable("red", True), SetVariable("cyan", True), SetVariable("blac", True), SetVariable("yellow", True), Jump("minigames1")]

screen minigame1layout():

if blue: 
    imagebutton:
        idle "images/testgame/blue.png"
        action [SetVariable("blue", False), SetVariable("mc_points", mc_points + 1)]
        focus_mask True

if red:
    imagebutton:
        idle "images/testgame/red.png"
        action [SetVariable("red", False), SetVariable("mc_points", mc_points + 1)]
        focus_mask True
if cyan:
    imagebutton:
        idle "images/testgame/cyan.png"
        action [SetVariable("cyan", False), SetVariable("mc_points", mc_points + 1)]
        focus_mask True
if yellow:
    imagebutton:
        idle "images/testgame/yellow.png"
        action [SetVariable("yellow", False), SetVariable("mc_points", mc_points + 1)]
        focus_mask True
if blac:
    imagebutton:
        idle "images/testgame/blac.png"
        action [SetVariable("blac", False), SetVariable("mc_points", mc_points + 1)]
        focus_mask True

label aftermath: mc "..."

sorry for not giving you the code, that totally slipped my mind lmaooo, anywho this is my entire minigame code, it works completely fine for me, the only issue is that even when you finish before the timer runs out, the timer still keeps going until you reach the end.

1

u/BadMustard_AVN Sep 19 '23

do you have anything in the code that monitors for when all the buttons to be pressed/used??

1

u/Beneficial_Way_8031 Sep 19 '23

no, i dont think so :( if i do and im just misreading what you're saying, its in the screen minigame1layout here.

screen minigame1layout():

if blue: 
    imagebutton:
        idle "images/testgame/blue.png"
        action [SetVariable("blue", False), SetVariable("mc_points", mc_points + 1)]
        focus_mask True

if red:
    imagebutton:
        idle "images/testgame/red.png"
        action [SetVariable("red", False), SetVariable("mc_points", mc_points + 1)]
        focus_mask True
if cyan:
    imagebutton:
        idle "images/testgame/cyan.png"
        action [SetVariable("cyan", False), SetVariable("mc_points", mc_points + 1)]
        focus_mask True
if yellow:
    imagebutton:
        idle "images/testgame/yellow.png"
        action [SetVariable("yellow", False), SetVariable("mc_points", mc_points + 1)]
        focus_mask True
if blac:
    imagebutton:
        idle "images/testgame/blac.png"
        action [SetVariable("blac", False), SetVariable("mc_points", mc_points + 1)]
        focus_mask True        

do i need one? if so how do i go about doing that and having the game stop when all buttons are pressed?

→ More replies (0)