Making a timer that is running in the background during the other label

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
myur
Newbie
Posts: 2
Joined: Fri Mar 08, 2024 6:47 pm
Contact:

Making a timer that is running in the background during the other label

#1 Post by myur »

Salvete, everyone, this is my first post on this forum, and im here with something that i havent quite managed to find too much discussion about.
Say, i want to make this interaction in the vnovel: while a certain label is being ran, if it is not finished in under x seconds, the game jumps to a different designated label. Now, i did dig up something about timers in Renpy, but those timers are only ran through screens - as in, i havent seen a single script that has them running in the background, which is exactly what im looking for. I was wondering if its even possible with Renpy, so help would be appreciated.
I also want to clarify that im a totes amateur in Renpy, so properly resetting the timer in case the label has actually been finished in under x seconds may be a bit problematic for me as well.
This is my current code, which, of course, doesnt work:

Code: Select all

label current_cutscene:
    $ time = x
    $ timer_range = x
    $ timer_jump = 'cutscene'
    # the events of the label are being ran #
    jump current_cutscene_continuation

label cutscene:
    # the label that is only ran in case the timer that is running in the background activates before the previous label is finished #

label current_cutscene_continuation:
    # here, im trying to reset/stop the timer, my best guess is calling a reset label like $ timer = None #
    # ... 
 

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Making a timer that is running in the background during the other label

#2 Post by xavimat »

Well, you have your answer already, but have discarded it, I'm not sure why: a timer running inside a screen.
You talk about "timer running through screens" as a different thing from a "timer running in the background". But they can be the exact same thing.
Maybe you are not aware of the two main uses of screens:
1. When you have a screen that needs user interaction, you use call screen screenname; this way, the game is locked by that screen until some action from that screen unlocks it. It can be Return(), Jump(), Call()... This is not what you need.
2. But there is a second way of using screens, usually they simply show information to the user and don't need any interaction. They don't lock the game and the dialogue lines of the label continue as usual, with the screen still visible. You use them with show screen screenname.
(There are more possibilities in between, with modals and more complex behaviors, but these are the two main ones).

In your case, you can use a screen that contains only a timer, and show it. The timer will run, as you say, in the background (that means, it does not block the normal flow of the label), and will execute the action when it ends. If the screen is hidden before the timer ends, nothing will happen.

Code: Select all

screen just_a_timer():
    timer 5 action Jump("too_slow")
label start:
    show screen just_a_timer
    "Hurry, hurry, read this quickly before the timer ends!!"
    "And this too"
    "And also this line. Hurry!"
    hide screen just_a_timer
    "Phew! You made it."
    "GOOD ENDING"
    return
label too_slow:
    hide screen just_a_timer
    "You where too slow..."
    "BAD ENDING"
    return
WARNING: You probably have thought about it, but it is a good idea to inform the player about this timer thing. Otherwise, they just would click and see "You where too slow..." without knowing what it's that about; they'd just assume that's the next line after the one they were reading.
ANOTHER WARNING: ...aaand probably you have thought about this too, but everyone has their own pace at reading, and enjoys reading and watching the images in many different ways and speeds. Be careful with this "read quickly" challenge, because it seems that the actual text loses its importance.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

myur
Newbie
Posts: 2
Joined: Fri Mar 08, 2024 6:47 pm
Contact:

Re: Making a timer that is running in the background during the other label

#3 Post by myur »

xavimat wrote: Mon Apr 08, 2024 1:42 pm Well, you have your answer already, but have discarded it, I'm not sure why: a timer running inside a screen.
You talk about "timer running through screens" as a different thing from a "timer running in the background". But they can be the exact same thing.
Maybe you are not aware of the two main uses of screens:
1. When you have a screen that needs user interaction, you use call screen screenname; this way, the game is locked by that screen until some action from that screen unlocks it. It can be Return(), Jump(), Call()... This is not what you need.
2. But there is a second way of using screens, usually they simply show information to the user and don't need any interaction. They don't lock the game and the dialogue lines of the label continue as usual, with the screen still visible. You use them with show screen screenname.
(There are more possibilities in between, with modals and more complex behaviors, but these are the two main ones).

In your case, you can use a screen that contains only a timer, and show it. The timer will run, as you say, in the background (that means, it does not block the normal flow of the label), and will execute the action when it ends. If the screen is hidden before the timer ends, nothing will happen.

Code: Select all

screen just_a_timer():
    timer 5 action Jump("too_slow")
label start:
    show screen just_a_timer
    "Hurry, hurry, read this quickly before the timer ends!!"
    "And this too"
    "And also this line. Hurry!"
    hide screen just_a_timer
    "Phew! You made it."
    "GOOD ENDING"
    return
label too_slow:
    hide screen just_a_timer
    "You where too slow..."
    "BAD ENDING"
    return
WARNING: You probably have thought about it, but it is a good idea to inform the player about this timer thing. Otherwise, they just would click and see "You where too slow..." without knowing what it's that about; they'd just assume that's the next line after the one they were reading.
ANOTHER WARNING: ...aaand probably you have thought about this too, but everyone has their own pace at reading, and enjoys reading and watching the images in many different ways and speeds. Be careful with this "read quickly" challenge, because it seems that the actual text loses its importance.
Thanks! I never really used "show screen" before, only "call screen", so this is news to me. Appreciate the help!
Regarding the warnings, i sure did insert an achtung advising to read the label in designated time. See, this timer is made specifically for a scene in storyline taking place in a setting that i thought i could add a cool touch to with an ambient-like music, which at some point transitions into black metal (which is just earrape, honestly) - and i needed this timer to proc when the music transitions, jumping to a label executing that "cool touch" simultaneously.

Post Reply

Who is online

Users browsing this forum: No registered users