Inactivity Timer in a RenPy Game
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.
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.
Inactivity Timer in a RenPy Game
Greetings. I have somewhat of an advanced question I'm hoping someone could help me with.
I'm currently trying to create a trivia game using the RenPy engine. So far I have everything down expect one small thing. I'd like the game to have an inactivity timer of sorts. Say, three minutes have passed and no buttons have been pressed ► send the player back to the main menu.
Is something like this possible? I am aware that you can use timers in RenPy. But how do I make it so that the timer starts if there's no activity on the player's part? Thanks in advance!
I'm currently trying to create a trivia game using the RenPy engine. So far I have everything down expect one small thing. I'd like the game to have an inactivity timer of sorts. Say, three minutes have passed and no buttons have been pressed ► send the player back to the main menu.
Is something like this possible? I am aware that you can use timers in RenPy. But how do I make it so that the timer starts if there's no activity on the player's part? Thanks in advance!
- Evildumdum
- Regular
- Posts: 191
- Joined: Sun Jan 18, 2015 8:49 am
- Projects: ApoclypseZ
- Contact:
Re: Inactivity Timer in a RenPy Game
You need a while loop. Set it to +1 to a variable then pause for a second. i'll knock you up a mock version.
Of course you can rig it up with screens and bars and such to make it pretty, but this is the basic idea.
Code: Select all
init:
Timer = 0
EndTime = 180
start:
python:
while Timer <= EndTime:
Timer += 1
renpy.pause(1)
"You Fail"
"If at first you don't succeed, try hitting it with a shoe."
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: Inactivity Timer in a RenPy Game
Actually, a screen might be better. since you can interact with the game while it's going on.
You can then do:
To start or reset the timer.
Code: Select all
screen main_menu_timer():
timer 180.0 action MainMenu(confirm=False)
label reset_timer():
hide screen main_menu_timer
show screen main_menu_timer
return
Code: Select all
call reset_timer
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- Evildumdum
- Regular
- Posts: 191
- Joined: Sun Jan 18, 2015 8:49 am
- Projects: ApoclypseZ
- Contact:
Re: Inactivity Timer in a RenPy Game
Lemme get out my note pad. I might use this myself.
"If at first you don't succeed, try hitting it with a shoe."
Re: Inactivity Timer in a RenPy Game
I want to use this for inactivty through the whole game. Is there a way to do it on clicks?
Like if someone hasn't clicked for five minutes it goes back to the main menu?
Like if someone hasn't clicked for five minutes it goes back to the main menu?
Re: Inactivity Timer in a RenPy Game
Any particular reason you want to do this? It's a game design choice that benefits nobody and can harm players who needed to go AFK. I genuinely don't recall a single game that I've ever played which would actually abandon game progress from player inaction during gameplay - and I think it's for good reasons.
I'd strongly recommend you don't do this.
If you do want to implement that, please make sure you save the game first. And you'll want to look into screen keys: https://www.renpy.org/doc/html/screens.html#key (look at the customising keymap page for the mouse keys)
Show the screen at all times, and have mouse click action call the reset_timer label.
I'd strongly recommend you don't do this.
If you do want to implement that, please make sure you save the game first. And you'll want to look into screen keys: https://www.renpy.org/doc/html/screens.html#key (look at the customising keymap page for the mouse keys)
Show the screen at all times, and have mouse click action call the reset_timer label.
Re: Inactivity Timer in a RenPy Game
Hi!
The reason I want to do this is because I made a game for an exhibition! So I wanted it to be able to restart in the case that a player abandoned the station halfway through. This way new players would be able to start right away! Makes sense?
The reason I want to do this is because I made a game for an exhibition! So I wanted it to be able to restart in the case that a player abandoned the station halfway through. This way new players would be able to start right away! Makes sense?
Re: Inactivity Timer in a RenPy Game
Fair enough. Have you read the documentation I linked? Do you need further help?
Re: Inactivity Timer in a RenPy Game
This seems to do the trick!
Posting it for anyone who would want to use it. (I realize I am in a very small minority hahah)
screen inactivity_timer():
timer 5.0 action MainMenu(confirm=False)
if 'mousedown_1':
call reset_timer
label reset_timer():
hide screen inactivity_timer
show screen inactivity_timer
Posting it for anyone who would want to use it. (I realize I am in a very small minority hahah)
screen inactivity_timer():
timer 5.0 action MainMenu(confirm=False)
if 'mousedown_1':
call reset_timer
label reset_timer():
hide screen inactivity_timer
show screen inactivity_timer
-
- Regular
- Posts: 27
- Joined: Fri Jul 08, 2016 6:53 am
- Contact:
Re: Inactivity Timer in a RenPy Game
I tried this code but the statement with if it cant be used.ketchup wrote: ↑Sun Apr 22, 2018 6:58 pm This seems to do the trick!
Posting it for anyone who would want to use it. (I realize I am in a very small minority hahah)
screen inactivity_timer():
timer 5.0 action MainMenu(confirm=False)
if 'mousedown_1':
call reset_timer
label reset_timer():
hide screen inactivity_timer
show screen inactivity_timer
After starting the game, the menu just go back to mainmenu. And if I start the game again, the screen statement doesnt repeat. Maybe the mousedown_1 is not correct?
Could somebody please help me to make it run for the latest version?
(I need this code for an exhibition! If the player dont play it again, the game should be reset to go back to mainmenu)
Re: Inactivity Timer in a RenPy Game
Try it like
Code: Select all
screen main_menu_timer():
timer 180.0 action MainMenu(confirm=False)
key 'dismiss' action [Hide("main_menu_timer"), Show("main_menu_timer")]
label start:
"..."
show screen main_menu_timer
"... ..."
"?!"
https://www.renpy.org/doc/html/screen_actions.html#Hide
-
- Regular
- Posts: 27
- Joined: Fri Jul 08, 2016 6:53 am
- Contact:
Re: Inactivity Timer in a RenPy Game
Thank you!Alex wrote: ↑Sat Jul 24, 2021 2:29 amTry it likehttps://www.renpy.org/doc/html/screens.html#keyCode: Select all
screen main_menu_timer(): timer 180.0 action MainMenu(confirm=False) key 'dismiss' action [Hide("main_menu_timer"), Show("main_menu_timer")] label start: "..." show screen main_menu_timer "... ..." "?!"
https://www.renpy.org/doc/html/screen_actions.html#Hide
But it doesnt run smoothly if I add the screen main_menu_timer in the label section. I can't play further after I add the screen main_menu_timer.
is it possible to use the function rollback?
Re: Inactivity Timer in a RenPy Game
Oops, lack of testing, sorry. Tryinitialzero wrote: ↑Sat Jul 24, 2021 5:29 am ...But it doesnt run smoothly if I add the screen main_menu_timer in the label section. I can't play further after I add the screen main_menu_timer....
Code: Select all
screen main_menu_timer():
timer 180.0 action MainMenu(confirm=False)
key 'dismiss' action [Hide("main_menu_timer"), Show("main_menu_timer"), Return()]
# or
# key 'mousedown_1' action [Hide("main_menu_timer"), Show("main_menu_timer")]
-
- Regular
- Posts: 27
- Joined: Fri Jul 08, 2016 6:53 am
- Contact:
Re: Inactivity Timer in a RenPy Game
Unfortunately nothing happens while playing the game.
I put the code before label start.
Is there a better solution to solve it?
I put the code before label start.
Is there a better solution to solve it?
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: Inactivity Timer in a RenPy Game
Here's my go at it, based on Alex's version.
In this version, calls to reset_timer reset the timer.
Note there's an accessibility issue here. While it might make sense to use this to reset a game in a demo setting, trying to increase game challenge with timers like this hurts people who might not speak the language the game is written in. (As well is people with cognitive disabilities, people with screaming children, etc.)
Code: Select all
screen activity_timer():
default warning = False
timer 10.0 action SetScreenVariable("warning", True)
timer 15.0 action MainMenu(confirm=False)
if warning:
text "Timeout in 5 seconds!"
label reset_timer:
hide screen activity_timer
show screen activity_timer
return
label start:
scene bg washington
call reset_timer
"First choice."
call reset_timer
"Hard mode - two choices, one timer."
"And choice 2."
call reset_timer
"Part 3."
return
Note there's an accessibility issue here. While it might make sense to use this to reset a game in a demo setting, trying to increase game challenge with timers like this hurts people who might not speak the language the game is written in. (As well is people with cognitive disabilities, people with screaming children, etc.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Who is online
Users browsing this forum: apocolocyntose, DewyNebula