[Solved] Text speed preview system bugs

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
KuroOneHalf
Regular
Posts: 129
Joined: Fri Apr 25, 2014 6:18 pm
Completed: Cuttlebone
Projects: Somewhere In The Shade
Deviantart: KuroOneHalf
itch: kuroonehalf
Contact:

[Solved] Text speed preview system bugs

#1 Post by KuroOneHalf »

I'm working on a text speed preview feature for the settings menu and have the core components working, but have some major bugs that I'm having a lot of trouble ironing out. The basic functionality is meant to be: String of text appears with the current text speed, waits a fraction of a second, and replays the text string from the beginning, continuously. If the text speed is instant (cps = 0 internally), it just displays the text without animation.

Current bugs:
- The text won't display immediately, and waits for the timer to time out once before displaying for the first time. I feel like there's a simple solution for this but I'm derping on what it is.
- When changing from a non-zero cps value to zero, the actual_text screen will be displayed twice, on top of itself. The fact that cps=0 uses "use" I think means the tag is ignored, and that's why we get the screen showing twice, but I haven't yet figured out a way to show that screen on top of the preferences screen without being triggered by an action. ;w;
- The text will stay on screen until it is finished displaying, even if I change screens in the middle. I know I can counter this by putting Hide actions on the navigation buttons, but it seems like a needlessly verbose solution. Is there nothing more elegant to solve this?

And an extra nuance I'd like it to have:
- Changing text speed should restart the text animation immediately. - I should be able to tie some action to the Changed property of the slider for text speed and do this, but it will be dependent on the solution to the problems above.

Code: Select all

screen preferences:
	use text_preview
init -2:
    $lorem_ipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean bibendum in urna vel dapibus. Nulla et urna imperdiet, feugiat ligula id."
screen text_preview:
    # If text speed is set to instant, just display it normally
    if _preferences.text_cps == 0:
        use actualtext
    # Otherwise, display it with the current text speed
    else:
        $ show_after = len(lorem_ipsum)/_preferences.text_cps + 0.6
        timer show_after repeat True action [Hide("actualtext"), ShowMenu("actualtext", animating=True)]

screen actualtext(animating=False):
    if animating:
        text lorem_ipsum slow_cps True style "say_dialogue"
        text "[_preferences.text_cps:.5] characters per second"
    else:
        text lorem_ipsum style "say_dialogue"
I've tried so much stuff and I'm kind of at my wits end. Any help would be super appreciated.
Last edited by KuroOneHalf on Fri Dec 06, 2019 4:52 pm, edited 1 time in total.

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Text speed preview system bugs

#2 Post by Kia »

for the delay, you can use: on "show"
in the screen, it will trigger the action when the screen is shown.

for the second problem, you can use a screen tag

and finally you can use hover/unhover to show and hide the preview screen depending on where your mouse is hovering but any use of those two excludes the touch users
there is variables that check if for example say screen is present, there should be one for preference as well, if you can find that one you can check for that or you can put the code inside the preference screen and use a variable and an if statement to show/hide it

User avatar
KuroOneHalf
Regular
Posts: 129
Joined: Fri Apr 25, 2014 6:18 pm
Completed: Cuttlebone
Projects: Somewhere In The Shade
Deviantart: KuroOneHalf
itch: kuroonehalf
Contact:

Re: Text speed preview system bugs

#3 Post by KuroOneHalf »

I ended up doing this with a DynamicDisplayable and it works great. One of the original wishlisted nuances isn't working - the one about restarting the text on changing text speed - but I think I'm fine with that. It might have looked janky to have the text restart a bunch as you moved the slider anyways.

Here's my final code, for those wanting to try something similar.

Code: Select all

screen preferences:
    use text_preview

screen text_preview:
    frame:
        add DynamicDisplayable(textpreview_displayable, style="textprev_text")

style textprev_text:
    take say_dialogue
        
init python:
    lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean bibendum in urna vel dapibus. Nulla et urna imperdiet, feugiat ligula id."
    lorem_len = len(lorem)
    def textpreview_displayable(st, at, **kwargs):
        global lorem
        global lorem_len

        extradelay = _preferences.text_cps * 0.5 # wait half a second before restarting
        result = int ((_preferences.text_cps * st) % (lorem_len + extradelay)) or lorem_len
        if _preferences.text_cps == 0: # Instant text
            return Text (kwargs.get('txt', lorem), **kwargs), None
        else: # Slow text
            return Text (kwargs.get('txt', lorem[:result]), **kwargs), 1/_preferences.text_cps

Post Reply

Who is online

Users browsing this forum: Google [Bot]