Time count

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
briannavon
Miko-Class Veteran
Posts: 505
Joined: Mon Mar 26, 2012 6:51 pm
Location: Philadelphia
Contact:

Time count

#1 Post by briannavon » Sun Jun 24, 2012 5:20 pm

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!
Join Me At LivingGame Productions!

http://livinggameproductions.blogspot.com/

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Time count

#2 Post by apricotorange » Sun Jun 24, 2012 6:40 pm

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

#3 Post by briannavon » Sun Jun 24, 2012 7:12 pm

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."
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."
Join Me At LivingGame Productions!

http://livinggameproductions.blogspot.com/

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Time count

#4 Post by apricotorange » Sun Jun 24, 2012 7:49 pm

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

#5 Post by briannavon » Sun Jun 24, 2012 8:11 pm

Can someone please help me with this :(
Join Me At LivingGame Productions!

http://livinggameproductions.blogspot.com/

User avatar
Michiyo6918
Veteran
Posts: 262
Joined: Fri Nov 11, 2011 12:26 am
Projects: ╮(╯▽╰)╭
Location: Look behind you
Contact:

Re: Time count

#6 Post by Michiyo6918 » Sun Jun 24, 2012 9:59 pm

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.
Last edited by Michiyo6918 on Mon Jun 25, 2012 3:08 pm, edited 1 time in total.
Tumblr | DA | Honest Critique
“如果那个人是神。
他想渎神。
——【黑匣子】”

briannavon
Miko-Class Veteran
Posts: 505
Joined: Mon Mar 26, 2012 6:51 pm
Location: Philadelphia
Contact:

Re: Time count (solved)

#7 Post by briannavon » Sun Jun 24, 2012 11:54 pm

It's fixed now! Thanks everybody! :D
Join Me At LivingGame Productions!

http://livinggameproductions.blogspot.com/

User avatar
Michiyo6918
Veteran
Posts: 262
Joined: Fri Nov 11, 2011 12:26 am
Projects: ╮(╯▽╰)╭
Location: Look behind you
Contact:

Re: Time count (solved)

#8 Post by Michiyo6918 » Mon Jun 25, 2012 12:24 am

briannavon wrote:It's fixed now! Thanks everybody! :D
That's good. Wish you luck on releasing the next demo of your game :)
Tumblr | DA | Honest Critique
“如果那个人是神。
他想渎神。
——【黑匣子】”

User avatar
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

#9 Post by TrickWithAKnife » Mon Jun 25, 2012 12:20 pm

I'm having a little trouble too.

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."
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.
"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.

User avatar
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

#10 Post by TrickWithAKnife » Mon Jun 25, 2012 12:51 pm

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.

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.

User avatar
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

#11 Post by PyTom » Mon Jun 25, 2012 6:20 pm

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
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
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

#12 Post by TrickWithAKnife » Mon Jun 25, 2012 9:11 pm

I've been using this code in my game, because I just need it rounded to the closest minute:

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
 
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.
    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.

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Time count

#13 Post by Showsni » Tue Jun 26, 2012 5:38 am

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)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot]