How to display percentage of your game completed/read

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
morg
Regular
Posts: 95
Joined: Sun May 10, 2015 7:35 am
Projects: Cupid's Affair
Tumblr: n-morg
Contact:

How to display percentage of your game completed/read

#1 Post by morg »

hi there!
I got the idea from a few visual novels where they show you how much of the game has been completed based on the read script. so I found the renpy.count_dialogue_blocks() and renpy.count_seen_dialogue blocks() functions and found out how you could use those functions to display a percentage completed counter.

to do that, first paste this before start

Code: Select all

init python:    
    def percent():
        global result
        result = seen * 100 / dialogue
and add this after start

Code: Select all

    $ result = 0
    $ dialogue = renpy.count_dialogue_blocks()
    $ seen = renpy.count_seen_dialogue_blocks()
then, when you want to use the function, add this

Code: Select all

    $ percent()
    "[result]\%"
notes:
- don't forget to add the backslash before the percent sign or else it will give you errors
- The documentation says:
This (the seen dialogue blocks) number may be larger than the result of renpy.count_dialogue_blocks() when the script has changed and older dialogue blocks are no longer accessible.
You can avoid this problem by deleting persistent data, and the player wouldn't encounter this anyway.
-the best place for this function is somewhere on a screen. If you want to do that though, don't forget to call the percent() function right before you call your screen.

that's it, I hope someone makes use of this!
Image

User avatar
minyan
Miko-Class Veteran
Posts: 630
Joined: Tue Feb 10, 2015 3:59 pm
Completed: Trial By Fire, Heartbaked, Ellaria, Plain, This My Soul, The Pretenders Guild
Projects: Arena Circus
Tumblr: minyanstudios
itch: harlevin
Contact:

Re: How to display percentage of your game completed/read

#2 Post by minyan »

morg wrote:hi there!
I got the idea from a few visual novels where they show you how much of the game has been completed based on the read script. so I found the renpy.count_dialogue_blocks() and renpy.count_seen_dialogue blocks() functions and found out how you could use those functions to display a percentage completed counter.

to do that, first paste this before start

Code: Select all

init python:    
    def percent():
        global result
        result = seen * 100 / dialogue
and add this after start

Code: Select all

    $ result = 0
    $ dialogue = renpy.count_dialogue_blocks()
    $ seen = renpy.count_seen_dialogue_blocks()
then, when you want to use the function, add this

Code: Select all

    $ percent()
    "[result]\%"
notes:
- don't forget to add the backslash before the percent sign or else it will give you errors
- The documentation says:
This (the seen dialogue blocks) number may be larger than the result of renpy.count_dialogue_blocks() when the script has changed and older dialogue blocks are no longer accessible.
You can avoid this problem by deleting persistent data, and the player wouldn't encounter this anyway.
-the best place for this function is somewhere on a screen. If you want to do that though, don't forget to call the percent() function right before you call your screen.

that's it, I hope someone makes use of this!

Hey! I tried out your code and it didn't quite work for me, but changing it to this did:

before start:

Code: Select all

init:
    default result = 0
    default dialogue = renpy.count_dialogue_blocks()
somewhere else (I have it in a separate script, but it should work wherever)

Code: Select all

init python:
     def percent():
            global result
            global dialogue
            seen = renpy.count_seen_dialogue_blocks()
            result = seen * 100 / dialogue

Then I was just able to use [result] to display it, no slash needed. Thanks for this though, it's a really handy feature! (I'm using renpy 6.99.10)
ImageImage

User avatar
scorlight
Regular
Posts: 67
Joined: Fri Sep 13, 2013 7:02 am
Contact:

Re: How to display percentage of your game completed/read

#3 Post by scorlight »

I only wrote this before start

Code: Select all

init:
    default seen = renpy.count_seen_dialogue_blocks()
    default dialogue = renpy.count_dialogue_blocks()
    default result = seen * 100 / dialogue
then in screen.rpy, in the screen main_menu I added this

Code: Select all

vbox:
        xpos 0.02 ypos 0.98
        xanchor 0.0 yanchor 1.0
        $ percent = "Finished: [result]%"
        text percent xalign 0.5
It looks like it can run normally O_o I wonder if there is any difference between this method and the one you guys mentioned
Artist for rent, see my art here: http://scorlight.deviantart.com/gallery/

Post Reply

Who is online

Users browsing this forum: No registered users