Displaying playtime

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
User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Displaying playtime

#1 Post by isobellesophia »

Hello

I am back for another question, can somebody help me of having the time counting of the game/playtime on screen?
And also, when the player finishes the game, or having the ending finished, the time will stop and it will display in the text dialogue for how much time consumed of playing that game. And quits the game.

Thanks for who could help.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Displaying playtime

#2 Post by Imperf3kt »

I'm not sure how useful it is to you but I use this on the save screen:

Code: Select all

init python:
    import time

## game runtime counter
default playtime = 0

init 2 python:

    def save_playtime(d):
        renpy.store.playtime += renpy.get_game_runtime()
        renpy.clear_game_runtime()
        d["playtime"] = renpy.store.playtime

    config.save_json_callbacks = [save_playtime]
    
    
    ############## The above can go anywhere in the screens file ############
    
    
                        text FileTime(slot, format=_("{#file_time}%A, %B %d %Y, %H:%M"), empty=_("empty slot")):
                            style "slot_time_text"
                            
                        $ playtime = FileJson(slot, "playtime", empty=0, missing=0) 
                        $ minutes, seconds = divmod(int(playtime), 60)
                        $ hours, minutes = divmod(minutes, 60)
                        text "Playtime: [hours:02d]:[minutes:02d].[seconds:02]":
                            style "slot_time_text"

style page_label is gui_label
style page_label_text is gui_label_text
style page_button is gui_button
style page_button_text is gui_button_text

style slot_button is gui_button
style slot_button_text is gui_button_text
style slot_time_text is slot_button_text
style slot_name_text is slot_button_text

style page_label:
    xpadding 50
    ypadding 3

style page_label_text:
    text_align 0.5
    layout "subtitle"
    hover_color gui.hover_color

style page_button:
    properties gui.button_properties("page_button")

style page_button_text:
    properties gui.button_text_properties("page_button")

style slot_button:
    properties gui.button_properties("slot_button")

style slot_button_text:
    properties gui.button_text_properties("slot_button")
It allows each save file to display its own runtime as text on the save screen.

Image
I imagine you could modify it to display at the end of a playthrough with minimal work.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Displaying playtime

#3 Post by isobellesophia »

Imperf3kt wrote: Sun Oct 06, 2019 6:03 am I'm not sure how useful it is to you but I use this on the save screen:

Code: Select all

init python:
    import time

## game runtime counter
default playtime = 0

init 2 python:

    def save_playtime(d):
        renpy.store.playtime += renpy.get_game_runtime()
        renpy.clear_game_runtime()
        d["playtime"] = renpy.store.playtime

    config.save_json_callbacks = [save_playtime]
    
    
    ############## The above can go anywhere in the screens file ############
    
    
                        text FileTime(slot, format=_("{#file_time}%A, %B %d %Y, %H:%M"), empty=_("empty slot")):
                            style "slot_time_text"
                            
                        $ playtime = FileJson(slot, "playtime", empty=0, missing=0) 
                        $ minutes, seconds = divmod(int(playtime), 60)
                        $ hours, minutes = divmod(minutes, 60)
                        text "Playtime: [hours:02d]:[minutes:02d].[seconds:02]":
                            style "slot_time_text"

style page_label is gui_label
style page_label_text is gui_label_text
style page_button is gui_button
style page_button_text is gui_button_text

style slot_button is gui_button
style slot_button_text is gui_button_text
style slot_time_text is slot_button_text
style slot_name_text is slot_button_text

style page_label:
    xpadding 50
    ypadding 3

style page_label_text:
    text_align 0.5
    layout "subtitle"
    hover_color gui.hover_color

style page_button:
    properties gui.button_properties("page_button")

style page_button_text:
    properties gui.button_text_properties("page_button")

style slot_button:
    properties gui.button_properties("slot_button")

style slot_button_text:
    properties gui.button_text_properties("slot_button")
It allows each save file to display its own runtime as text on the save screen.

Image
I imagine you could modify it to display at the end of a playthrough with minimal work.
Im sorry to say, but when i tried this, the playtime wont count as i play fowardly the game, is there any i can use to work?
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Displaying playtime

#4 Post by isobellesophia »

Imperf3kt wrote: Sun Oct 06, 2019 6:03 am I'm not sure how useful it is to you but I use this on the save screen:
Im sorry to say, is there any code i can use? This one does not work, it doesnt count the playtime as i tried it.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Displaying playtime

#5 Post by Imperf3kt »

Sorry, its something I lifted from a cookbook entry.
I'm not too well versed in the json behind it (or at all, really)

Perhaps somebody else can help further.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Displaying playtime

#6 Post by isobellesophia »

Imperf3kt wrote: Sun Oct 06, 2019 6:22 am Sorry, its something I lifted from a cookbook entry.
I'm not too well versed in the json behind it (or at all, really)

Perhaps somebody else can help further.
Nvm, you edited the code, thanks for the help!
I am a friendly user, please respect and have a good day.


Image

Image


Post Reply

Who is online

Users browsing this forum: No registered users