Different Text speed for each characters and how to retrieve preference("text speed") value ?

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.
Message
Author
Dav
Regular
Posts: 28
Joined: Sun Nov 25, 2018 7:57 am
Projects: Fancy Future
Contact:

Different Text speed for each characters and how to retrieve preference("text speed") value ?

#1 Post by Dav » Sun Feb 28, 2021 11:07 pm

Hello !

Renpy's driving me crazy so far lol the documentation doesn't help... Or i'm too much of a noob to find anything in it ?

So actually i'm trying to do 2 things :

1 : i want to use the value of the text speed (and other sliders as well) to create a fake "animated" effect... This is pretty easy to do in C language, just print one picture when the values are odds, and another when they're even, so when we move the bar, the 2 animations succeed to each other creating a kind of movement.
I want to do that here... However i'm not even able to find how to GET the value of the text speed...
If i try to do it next to the bar... it doesn't work, and i'm not able to get the preferences.text_cps value neither the preference("text speed") value...
So i create that : (hoping to use one after another on a IF condition depending on value returned by the bar/slider)

Code: Select all

style pref_bar:
    left_gutter 3
    right_gutter 3
    yalign 0.5
    xysize (550, 40)
    left_bar Frame("gui/slider/horizontal_hover_bar.png", 4, 0)
    right_bar Frame("gui/slider/horizontal_idle_bar.png", 4, 0)
    thumb "gui/slider/horizontal_[prefix_]thumb.png"

style pref_bar1:
    left_gutter 3
    right_gutter 3
    yalign 0.5
    xysize (550, 40)
    left_bar Frame("gui/slider/horizontal_hover_bar.png", 4, 0)
    right_bar Frame("gui/slider/horizontal_idle_bar.png", 4, 0)
    thumb "gui/slider/horizontal_[prefix_]thumb1.png"
Then

Code: Select all

                vbox:

                    spacing 35
                    hbox:
                        spacing 10
                        bar:
                            style "pref_bar"
                            value Preference("text speed")
And here i cannot add another "value" line to send the value to another variable...
I can't either get the Preference("text speed") value, neither the Preferences.text_cps value, even indirectly... How do we get those values ? what am i doing wrong ?


2 : Is there a way to define a different text speed for each character (simulating characters that speak slowly or fastly), and use the global preference text speed as a multiplier for these relative character text speed ? i find nothing about this...

Thanks to anyone that could help !

Edit, so far i tried to print, in the text, as a variable :

Code: Select all

"Text Speed [gui.preference("text_cps")]"
"Text Speed [gui.preference("text_speed")]"
"Text Speed [gui.preference("text.cps")]"
"Text Speed [gui.preference("text.speed")]"
"Text Speed [gui.preference(text_cps)]"
"Text Speed [gui.preference(text_speed)]"
"Text Speed [gui.preference(text.cps)]"
"Text Speed [gui.preference(text.speed)]"
"Text Speed [gui.preferences("text_cps")]"
"Text Speed [gui.preferences("text_speed")]"
"Text Speed [gui.preferences("text.cps")]"
"Text Speed [gui.preferences("text.speed")]"
"Text Speed [gui.preferences(text_cps)]"
"Text Speed [gui.preferences(text_speed)]"
"Text Speed [gui.preferences(text.cps)]"
"Text Speed [preferences(text.speed)]"
"Text Speed [preference("text_cps")]"
"Text Speed [preference("text_speed")]"
"Text Speed [preference("text.cps")]"
"Text Speed [preference("text.speed")]"
"Text Speed [preference(text_cps)]"
"Text Speed [preference(text_speed)]"
"Text Speed [preference(text.cps)]"
"Text Speed [preference(text.speed)]"
"Text Speed [preferences("text_cps")]"
"Text Speed [preferences("text_speed")]"
"Text Speed [preferences("text.cps")]"
"Text Speed [preferences("text.speed")]"
"Text Speed [preferences(text_cps)]"
"Text Speed [preferences(text_speed)]"
"Text Speed [preferences(text.cps)]"
"Text Speed [preferences(text.speed)]"
Running out of ideas and patience...

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#2 Post by zmook » Mon Mar 01, 2021 3:48 pm

1. I don't understand why you're trying to fake an animated effect, when renpy has plenty of real animations that seem like they would do exactly what you want.

2. The value of the default text speed is `preferences.text_cps` (https://www.renpy.org/doc/html/preferences.html)

To set text speed per character, you want one of these two:

Code: Select all

define j = Character("Jack", what_slow_cps=5) # set the specified cps  
define e = Character("Eileen", what_slow_cps_multiplier=5) # multiply the default cps chosen by the player
Note that in the second case, if the game is set to instant text, it uses cps=0 for that, so any multiplier applied to instant is still instant.

* text styles: https://www.renpy.org/doc/html/style_pr ... properties
* applying text styles to particular characters: https://www.renpy.org/doc/html/dialogue ... #Character
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Dav
Regular
Posts: 28
Joined: Sun Nov 25, 2018 7:57 am
Projects: Fancy Future
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#3 Post by Dav » Mon Mar 01, 2021 11:23 pm

zmook wrote:
Mon Mar 01, 2021 3:48 pm
1. I don't understand why you're trying to fake an animated effect, when renpy has plenty of real animations that seem like they would do exactly what you want.
Wait there is a fonction in renpy to have animated bars/sliders ? i haven't read anything about that, do you know its name ?
zmook wrote:
Mon Mar 01, 2021 3:48 pm
2. The value of the default text speed is `preferences.text_cps` (https://www.renpy.org/doc/html/preferences.html)
Yes, but how do you retrieve that value, like if you want to print it in game, or store it in a variable ?
zmook wrote:
Mon Mar 01, 2021 3:48 pm
To set text speed per character, you want one of these two:

Code: Select all

define j = Character("Jack", what_slow_cps=5) # set the specified cps  
define e = Character("Eileen", what_slow_cps_multiplier=5) # multiply the default cps chosen by the player
Note that in the second case, if the game is set to instant text, it uses cps=0 for that, so any multiplier applied to instant is still instant.
That's perfect !!! thank you very much, that's exactly what i was looking for, i don't know how i didn't stumbled upon "what_slow_cps_multiplier", it's been like 2 months i'm reading renpy's docs >_<
edit : I just searched for "what_slow_cps_multiplier" and renpy documentation returned zero result :/ is that the good name or is there a typo or something ?
zmook wrote:
Mon Mar 01, 2021 3:48 pm
* text styles: https://www.renpy.org/doc/html/style_pr ... properties
* applying text styles to particular characters: https://www.renpy.org/doc/html/dialogue ... #Character
Not sure this will help me yet, the only "dynamic" thing i plan to do is to change the character name's color depending on its feeling toward the player ^^ but thanks !

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

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#4 Post by Imperf3kt » Tue Mar 02, 2021 12:00 am

Dav wrote:
Mon Mar 01, 2021 11:23 pm
zmook wrote:
Mon Mar 01, 2021 3:48 pm
2. The value of the default text speed is `preferences.text_cps` (https://www.renpy.org/doc/html/preferences.html)
Yes, but how do you retrieve that value, like if you want to print it in game, or store it in a variable ?
You can get the text_cps value and display it in a screen the same way as the other preference variables.
This is the way I was shown recently that works well for me.
viewtopic.php?f=8&t=60412#p535359

I'm not currently at a PC, so don't have access to the exact code I used, but if you need an example, one can be found in my Android GUI (version 1.25 and onwards) linked in my signature. Just find the preferences screen and search for text_cps
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#5 Post by zmook » Tue Mar 02, 2021 12:08 am

Dav wrote:
Mon Mar 01, 2021 11:23 pm
Wait there is a fonction in renpy to have animated bars/sliders ? i haven't read anything about that, do you know its name ?
It sounds like you want a Bar with an AnimatedValue:

Code: Select all

screen animvalbar():
    vbox:
        xmaximum 300
        bar value AnimatedValue(value=hp, range=max_hp, delay=2.0)
        text "HP: [hp]/[max_hp]" 
        
label bardemo:
    show screen animvalbar()
    "Now we do the animated value bar."
    $hp += 25
    "Adding 25."
    $hp -= 25
    "Subtracting 25."
    hide screen animvalbar  
This is copied from trooper6's demo here: viewtopic.php?t=30970
Yes, but how do you retrieve that value, like if you want to print it in game, or store it in a variable ?
Like this?

Code: Select all

	$ doublespeed = preferences.text_cps * 2
	eileen "I can type [preferences.text_cps] characters per second"
That's perfect !!! thank you very much, that's exactly what i was looking for, i don't know how i didn't stumbled upon "what_slow_cps_multiplier", it's been like 2 months i'm reading renpy's docs >_<
edit : I just searched for "what_slow_cps_multiplier" and renpy documentation returned zero result :/ is that the good name or is there a typo or something ?

It's in the links I pasted before:

"Character() … Styling Text and Windows. Keyword arguments beginning with who_, what_, and window_ have their prefix stripped, and are used to style the character name, the spoken text, and the window containing both, respectively." https://www.renpy.org/doc/html/dialogue ... #Character

Then 'slow_cps' and 'slow_cps_multiplier' are Text Style Properties.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Dav
Regular
Posts: 28
Joined: Sun Nov 25, 2018 7:57 am
Projects: Fancy Future
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#6 Post by Dav » Tue Mar 02, 2021 9:50 am

Imperf3kt wrote:
Tue Mar 02, 2021 12:00 am
You can get the text_cps value and display it in a screen the same way as the other preference variables.
This is the way I was shown recently that works well for me.
viewtopic.php?f=8&t=60412#p535359

I'm not currently at a PC, so don't have access to the exact code I used, but if you need an example, one can be found in my Android GUI (version 1.25 and onwards) linked in my signature. Just find the preferences screen and search for text_cps
So i tried for music volume, and it works just fine, then i tried to figure it out for text speed, and all i get is "preferences object has no attribute ...[...]"...
Tried

Code: Select all

$ txtspd = _preferences.get_text_speed("cps")
$ txtspd = _preferences.get_text("speed")
$ txtspd = _preferences.get_speed("text")
$ txtspd = _preferences.get_cps
$ txtspd = _preferences.get_cps("text_speed")
$ txtspd = _preferences.get_cps("text speed")
$ txtspd = _preferences.get_text_speed
And more...
Of course i spent another useless 2-3 hours in the renpy documentation with the worst research system possible that just puts implicit "OR" so when i type preferences.get, i have to check EVERY ARTICLES that contains either get, either preferences... this is driving me crazy i hate that documentation so much it hurts.
i cannot find any informations about the preferences object which is, if i understood well, different than the preference fonction. (well i found a lot of things about preferences, but nothing about a get nor anything related to game variables stored in it...

Thanks for your help anyway ^^

Dav
Regular
Posts: 28
Joined: Sun Nov 25, 2018 7:57 am
Projects: Fancy Future
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#7 Post by Dav » Tue Mar 02, 2021 9:53 am

zmook wrote:
Tue Mar 02, 2021 12:08 am
It sounds like you want a Bar with an AnimatedValue:
Well it's not the same, i don't want to animate a bar, i want to put an animation on the "thumb" of the bar when the user moves it ^^
zmook wrote:
Tue Mar 02, 2021 12:08 am
It's in the links I pasted before:

"Character() … Styling Text and Windows. Keyword arguments beginning with who_, what_, and window_ have their prefix stripped, and are used to style the character name, the spoken text, and the window containing both, respectively." https://www.renpy.org/doc/html/dialogue ... #Character

Then 'slow_cps' and 'slow_cps_multiplier' are Text Style Properties.
OMG i see my stupidity there, i'm sincerely sorry, i was trying to make something out of renpy for like 26hours straight when i answered you, i didn't figure that out... i understood in the meantime and will try it today, thank you very much for your help, and sorry again for being this dumb in my previous answer :/

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#8 Post by zmook » Tue Mar 02, 2021 1:18 pm

Dav wrote:
Tue Mar 02, 2021 9:53 am
Well it's not the same, i don't want to animate a bar, i want to put an animation on the "thumb" of the bar when the user moves it ^^
One of Bar's properties is "thumb" that can take a displayable. You can either create your own animated gif or movie and set it, or use ren'py ATL to make one:

Code: Select all

image anithumb:
        size (20,40)
        "003.jpg"
         pause 0.5
         "004.jpg"
         pause 0.5
         repeat
        
screen animvalbar():
    vbox:
        xmaximum 300
        bar value AnimatedValue(value=hp, range=max_hp, delay=2.0):
            thumb "anithumb"
That's a bar with a thumb that blinks constantly. If you want one that animates only when you're dragging it, bars have a hovered property that runs an action:

Code: Select all

        bar value AnimatedValue(value=hp, range=max_hp, delay=2.0):
            thumb "anithumb"
            hovered Function(func_name, True)
            unhovered Function(func_name, False)
The part I'm not sure about is the best way to wire up the hovered/unhovered action to change the thumb. Anyone have a suggestion?
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#9 Post by zmook » Tue Mar 02, 2021 1:23 pm

Dav wrote:
Tue Mar 02, 2021 9:50 am
Of course i spent another useless 2-3 hours in the renpy documentation with the worst research system possible that just puts implicit "OR" so when i type preferences.get, i have to check EVERY ARTICLES that contains either get, either preferences... this is driving me crazy i hate that documentation so much it hurts.
Use the google, man. https://www.google.com/search?q=renpy+t ... preference

The first hit has what you want.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

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

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#10 Post by Imperf3kt » Tue Mar 02, 2021 3:18 pm

There's always the general index, which I find quite handy.
https://www.renpy.org/doc/html/genindex.html
Press F3 or hold CTRL and press F, with that page open to search for what you're looking for.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

Dav
Regular
Posts: 28
Joined: Sun Nov 25, 2018 7:57 am
Projects: Fancy Future
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#11 Post by Dav » Wed Mar 03, 2021 4:48 am

zmook wrote:
Tue Mar 02, 2021 1:18 pm
One of Bar's properties is "thumb" that can take a displayable. You can either create your own animated gif or movie and set it, or use ren'py ATL to make one:

That's a bar with a thumb that blinks constantly. If you want one that animates only when you're dragging it, bars have a hovered property that runs an action:

The part I'm not sure about is the best way to wire up the hovered/unhovered action to change the thumb. Anyone have a suggestion?
Thank you very much for your help, i'll try things today, and will update it here once i found something satisfying ^^

Dav
Regular
Posts: 28
Joined: Sun Nov 25, 2018 7:57 am
Projects: Fancy Future
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#12 Post by Dav » Wed Mar 03, 2021 4:56 am

zmook wrote:
Tue Mar 02, 2021 1:23 pm

Use the google, man. https://www.google.com/search?q=renpy+t ... preference

The first hit has what you want.
Well, i did it and checked that page already (first post i mention these fonctions), and that returned the preferences, but doesn't mention any preferences.getXXX, nor the way to get the fonction... HOWEVER with your help (and imperfekt) i understood the problem i had...
I tried to use the preference object, using a fonction, INTO another fonction :

Code: Select all

"Text Speed [preferences.text_cps]"
While when using the same format as the example given previously :

Code: Select all

$ variable = preferences.text_cps
THEN using this variable

Code: Select all

"text speed [variable]"
Worked just fine.
Maybe i got bad habits of the previous languages i learned, but this direct adressing not working while indirect adressing working... Didn't came to my mind at all...

Thank you very much for your patience and kindness toward my stupidity, you really helped me a lot there !
Wish you the best !
Last edited by Dav on Wed Mar 03, 2021 4:57 am, edited 1 time in total.

Dav
Regular
Posts: 28
Joined: Sun Nov 25, 2018 7:57 am
Projects: Fancy Future
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#13 Post by Dav » Wed Mar 03, 2021 4:56 am

Imperf3kt wrote:
Tue Mar 02, 2021 3:18 pm
There's always the general index, which I find quite handy.
https://www.renpy.org/doc/html/genindex.html
Press F3 or hold CTRL and press F, with that page open to search for what you're looking for.
I don't know how i didn't stumbled upon that after spending so much time in the documentation... this goes into bookmarks, thank you ! ^^
Btw isn't it weird that the fonction you mentioned in the post linked (_preferences.get_volume("music")) isn't mentioned anywhere in the documentation nor the index ?_?

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

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#14 Post by Imperf3kt » Wed Mar 03, 2021 9:04 am

Dav wrote:
Wed Mar 03, 2021 4:56 am
Btw isn't it weird that the fonction you mentioned in the post linked (_preferences.get_volume("music")) isn't mentioned anywhere in the documentation nor the index ?_?
Yes, there's a few things missing from the index, but overall it does have most things.

And since I'm at my PC right now, with Ren'Py open, here's some additional code that may help.

Code: Select all

screen text_settings():

    python:
        txtspd = _preferences.text_cps
        afmtm = _preferences.afm_time

    hbox:
        style_prefix "slider"
        box_wrap True

        vbox:

            label _("Text Speed")

            bar value Preference("text speed") tooltip _("Adjust the speed text appears on screen in characters per second")
            if txtspd > 0:
                text _("{:.0f}".format(txtspd) )
            elif txtspd == 0:
                text _("Instant")

            label _("Auto-Forward Time")

            bar value Preference("auto-forward time") tooltip _("Adjust wait time before automatically advancing the game")
            text _("{:.0f}".format(afmtm) )

            textbutton _("Reset to default"):
                action Preference("text speed", 60), Preference("auto-forward time", 15)
                tooltip _("Reset text settings to default")
I can explain further what this is intended to do and how it works, but you seem to have some basic understanding or higher of programming, so you should be able to understand it I assume. If not, just say and I'll go over it for you.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Different Text speed for each characters and how to retrieve preference("text speed") value ?

#15 Post by zmook » Wed Mar 03, 2021 11:59 am

Imperf3kt wrote:
Wed Mar 03, 2021 9:04 am

Code: Select all

    python:
        txtspd = _preferences.text_cps
        afmtm = _preferences.afm_time
Just to add for the record, `preferences` and `_preferences` are aliases to the same object. By python idiom, the one with the underscore prefix is meant to be treated as private, so if you aren't PyTom it's preferred to use plain `preferences`. (In theory future Ren'Py could add getter or setter functions or something that would make them not identical.)
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Post Reply

Who is online

Users browsing this forum: Bing [Bot]