Time count
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.
-
briannavon
- Miko-Class Veteran
- Posts: 505
- Joined: Mon Mar 26, 2012 6:51 pm
- Location: Philadelphia
- Contact:
Time count
How do I make a game count the time in minutes that a players plays it so that I can put this:
You finished the demo in _____. Congrats!
You finished the demo in _____. Congrats!
-
apricotorange
- Veteran
- Posts: 479
- Joined: Tue Jun 05, 2012 2:01 am
- Contact:
Re: Time count
Code: Select all
$ minutes, seconds = divmod(int(renpy.get_game_runtime()), 60)
"It took you [minutes] minutes and [seconds] seconds to finish this demo."
-
briannavon
- Miko-Class Veteran
- Posts: 505
- Joined: Mon Mar 26, 2012 6:51 pm
- Location: Philadelphia
- Contact:
Re: Time count
It does not seem to be counting the time played. No matter how long I play it, it says "It took you 0 minutes and 0 seconds to finish this demo."apricotorange wrote:Code: Select all
$ minutes, seconds = divmod(int(renpy.get_game_runtime()), 60) "It took you [minutes] minutes and [seconds] seconds to finish this demo."
-
apricotorange
- Veteran
- Posts: 479
- Joined: Tue Jun 05, 2012 2:01 am
- Contact:
Re: Time count
That's strange... that exact code appears to work just fine for me.
-
briannavon
- Miko-Class Veteran
- Posts: 505
- Joined: Mon Mar 26, 2012 6:51 pm
- Location: Philadelphia
- Contact:
Re: Time count
Can someone please help me with this 
- Michiyo6918
- Veteran
- Posts: 262
- Joined: Fri Nov 11, 2011 12:26 am
- Projects: ╮(╯▽╰)╭
- Location: Look behind you
- Contact:
Re: Time count
Strange... that same code works for me perfectly.
Can you show me the script where you put the code? Remember those two lines should be put at the end of your demo.
Can you show me the script where you put the code? Remember those two lines should be put at the end of your demo.
Last edited by Michiyo6918 on Mon Jun 25, 2012 3:08 pm, edited 1 time in total.
-
briannavon
- Miko-Class Veteran
- Posts: 505
- Joined: Mon Mar 26, 2012 6:51 pm
- Location: Philadelphia
- Contact:
Re: Time count (solved)
It's fixed now! Thanks everybody! 
- Michiyo6918
- Veteran
- Posts: 262
- Joined: Fri Nov 11, 2011 12:26 am
- Projects: ╮(╯▽╰)╭
- Location: Look behind you
- Contact:
Re: Time count (solved)
That's good. Wish you luck on releasing the next demo of your gamebriannavon wrote:It's fixed now! Thanks everybody!
- TrickWithAKnife
- Eileen-Class Veteran
- Posts: 1261
- Joined: Fri Mar 16, 2012 11:38 am
- Projects: Rika
- Organization: Solo (for now)
- IRC Nick: Trick
- Location: Tokyo, Japan
- Contact:
Re: Time count
I'm having a little trouble too.
Here is the exact code I'm using:
It seems to work, but only between "The timer should start from now." and "Let this run for a bit".
Is there any way to keep it running while other things happen? This code would be extremely useful to me if it could do that.
Here is the exact code I'm using:
Code: Select all
label start:
scene black
"The timer should start from now"
$ minutes, seconds = divmod(int(renpy.get_game_runtime()), 60)
"Let this run for a bit"
"Let it run a little more, so it uses time."
"Ok, now let's see the result."
"It took you [minutes] minutes and [seconds] seconds to finish this demo."
Is there any way to keep it running while other things happen? This code would be extremely useful to me if it could do that.

"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.
If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.
If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.
- TrickWithAKnife
- Eileen-Class Veteran
- Posts: 1261
- Joined: Fri Mar 16, 2012 11:38 am
- Projects: Rika
- Organization: Solo (for now)
- IRC Nick: Trick
- Location: Tokyo, Japan
- Contact:
Re: Time count
Nevermind, I figured it out too. I thought the timer started from the first line of code, not from when the game started, until I read Michiyo6918's message again.
I just set up a couple of variables to record the start of the timed section, and took that time away from the end of the timed section.
I just set up a couple of variables to record the start of the timed section, and took that time away from the end of the timed section.
Code: Select all
"The timer should start next"
$ temp_minutes, temp_seconds = divmod(int(renpy.get_game_runtime()), 60)
"The actual gameplay that you want to time should go here."
$ temp_minutes2, temp_seconds2 = divmod(int(renpy.get_game_runtime()), 60)
$ minutes = temp_minutes2 - temp_minutes
$ seconds = temp_seconds2 - temp_seconds
"It took you [minutes] minutes and [seconds] seconds to finish this demo."

"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.
If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.
If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.
- PyTom
- Ren'Py Creator
- Posts: 15893
- 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: Time count
Note that that code is wrong, since you can wind up with a negative number of seconds. Your best bet is to subtract the seconds first, and then do the divmod.
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?)
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom
- TrickWithAKnife
- Eileen-Class Veteran
- Posts: 1261
- Joined: Fri Mar 16, 2012 11:38 am
- Projects: Rika
- Organization: Solo (for now)
- IRC Nick: Trick
- Location: Tokyo, Japan
- Contact:
Re: Time count
I've been using this code in my game, because I just need it rounded to the closest minute:
But I know people check these topics for their own problems, so maybe I should add the code other people would use.
I was a little confused about what you meant though, so I hacked together my own ugly way of doing it.
Code: Select all
$ temp_minutes2, temp_seconds2 = divmod(int(renpy.get_game_runtime()), 60) # To record the current gameplay time.
$ minutes = temp_minutes2 - temp_minutes # To figure out how many minutes the search took.
$ seconds = temp_seconds2 - temp_seconds # To figure out how many seconds the search took.
if seconds > 30: # Rounding up to the nearest minute.
$ minutes += 1
if seconds < -30: # Strangely, sometimes the seconds show as negative numbers. This will counteract that.
$ minutes += 1
I was a little confused about what you meant though, so I hacked together my own ugly way of doing it.
Code: Select all
$ temp_minutes2, temp_seconds2 = divmod(int(renpy.get_game_runtime()), 60) # To record the current gameplay time.
$ minutes = temp_minutes2 - temp_minutes # To figure out how many minutes the search took.
if temp_seconds2 >= temp_seconds:
$ seconds = temp_seconds2 - temp_seconds # To figure out how many seconds the search took.
else:
$ seconds = temp_seconds - temp_seconds2 # To figure out how many seconds the search took.

"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.
If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.
If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.
Re: Time count
PyTom means just get the raw runtime both times and only divmod it at the end if you want to put it into minutes.
$ firsttime = renpy.get_game_runtime()
"Lalala"
$ secondtime = renpy.get_game_runtime()
$ minutes, seconds = divmod(int(secondtime-firsttime), 60)
$ firsttime = renpy.get_game_runtime()
"Lalala"
$ secondtime = renpy.get_game_runtime()
$ minutes, seconds = divmod(int(secondtime-firsttime), 60)
Who is online
Users browsing this forum: Bing [Bot], Majestic-12 [Bot]
