Ren'Py Best way to display tokenized Text in Renpy/Python?

DiviDreamer

Member
Aug 29, 2020
249
215
Hi,
I'm looking for better or best Way to display tokenized Text in Renpy
without NVL and native sayer. Something like typewriter effect (not console stdout)
Maybe there is some libs for this? I never worked with tokenized Text before
so need your advise.
 

DiviDreamer

Member
Aug 29, 2020
249
215
Do you know what token is?
in your example just fist in text chain would be shown,

about console and stdout
$ print("hello there")
and press shift+o in renpy
 

DiviDreamer

Member
Aug 29, 2020
249
215
A bit info:


One of part of my renpy project generate chain of words that look something like that

body = {
"Imagine", "you're", "trying", "to", "teach", "a", "child", "to", "read" }

The goal is to show full sentence word by word like typewriter effect
when word tokens arrive into a beautiful book page with margins and new line.
I can't combine it into one string as word tokens arrive all the time
and i need to show them as soon as they in buffer.
It's actually very close to SSE server-sent events and i looking for good way to show words tokens
without waiting all text file to arrive.
 

Quintillian

Newbie
Apr 15, 2019
94
196
Interesting. Well, typewriter effects aren’t something new. I’m sure there are many tutorials out there. But I’m assuming the idea here is to display it on a custom screen, not on dialogue. I’m curious why words are arriving all the time. This implies the server is sending out data continuously. What’s the use case of this? I mean, from the user experience point of view, what is happening on their screens? For example, they click ‘book’, a screen appears and words start pouring from a server endlessly, is that it? And on that note, how’s the server sending the data, REST, sockets, or some other thingy?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,124
14,803
Do you know what token is?
I know what tokens mean, as I know that it have no meaning in the context you used it...


about console and stdout
$ print("hello there")
and press shift+o in renpy
I haven't asked what you meant by console stdout, but what it had to do with the rest of your question...


The goal is to show full sentence word by word like typewriter effect
Typewriters do not show the text word by word, by letter by letter...


when word tokens arrive into a beautiful book page with margins and new line.
I can't combine it into one string as word tokens arrive all the time
and i need to show them as soon as they in buffer.
Oh, so, what you want is to display a string that would update itself in real time...

Python:
define whatever = ""

screen mySelfUpdatingText():
    text "[whatever]"

label whatever:
    show screen mySelfUpdatingText

    [whatever you code you want to update the 'whatever' variable]

It's actually very close to SSE server-sent events and i looking for good way to show words tokens
without waiting all text file to arrive.
And why the text wouldn't arrive as a whole ?

If it's sent through network, then the tokens would be around ~980 BYTE long, what is big for "tokens"... At least unless you explicitly ask the server to split the text into words, what, for something small enough to be displayed in a screen, would be counter productive because way too slow.
If it come from a file, there's no way to ask the content word by word, and asking the content character by character would always be slower than asking the content as a whole. This while asking the content as a whole wouldn't be slow enough to justify partial updates.
It's only if the data come from the keyboard, or any similar device, that it could possibly make sense. Yet, only if it works at key level, because at word level it would just be ridiculous.
 

DiviDreamer

Member
Aug 29, 2020
249
215
define whatever = "" screen mySelfUpdatingText(): text "[whatever]" label whatever: show screen mySelfUpdatingText [whatever you code you want to update the 'whatever' variable]
Emm self updating string is close enough idea but a bit ineffective
as my whatever variable will look like this each update

Imagine
Imagine you're
Imagine you're trying
Imagine you're trying to
Imagine you're trying to teach
Imagine you're trying to teach a
Imagine you're trying to teach a child
Imagine you're trying to teach a child to read

Right?

i want to do something like this:

[Arrive buffer]
Imagine

[Output]
Imagine

[Arrive buffer]
you're

[Output]
Imagine you're

[Arrive buffer]
trying

[Output]
Imagine you're trying

[Arrive buffer]
to teach

[Output]
Imagine you're trying to teach
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,124
14,803
The code is four lines long, and coming with a test code would only need five more lines...
Python:
label whatever:
    show screen mySelfUpdatingText

    pause
    $ whatever += " something more"
    pause
    $ whatever += " yet something more"
    pause
Why not try before assuming ?
 
  • Like
Reactions: DiviDreamer

DiviDreamer

Member
Aug 29, 2020
249
215
The code is four lines long, and coming with a test code would only need five more lines...
No, i got it first time, just a bit worry of constantly growing variable,
i guess it's time for more testing..
Oh and thanks.
Btw i already tried something you advise before and have a problem with screen mySelfUpdatingText
refreshing, even with renpy.restart_interaction() ?
 

Quintillian

Newbie
Apr 15, 2019
94
196
And on that note, how’s the server sending the data, REST, sockets, or some other thingy?
You didn’t answer my question about how are you getting these tokens.

But also in any case, I guess, my question is still why are you receiving word by word? What is stoping you from getting the whole thing first and then show it one at a time?
 

DiviDreamer

Member
Aug 29, 2020
249
215
You didn’t answer my question about how are you getting these tokens.

But also in any case, I guess, my question is still why are you receiving word by word? What is stoping you from getting the whole thing first and then show it one at a time?
Well, i can't give you all detail for now
but it's made for user for convenient reason, so the user can start reading
when just few words already appears on book page than wait 30-40 seconds for whole text arrive and instantly appears.
 

DiviDreamer

Member
Aug 29, 2020
249
215
Well, everything i need help with already specified, and no detail because there is no much to tell it's very early project.
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,109
3,377
No luck, tokens arrive too fast, and Renpy don't update screen until last token arrive.
1. put the arriving tokens into a list.
2. use a screen repeating timer action to call a function on a regular interval
3. the function pops the oldest token from the head of the list, and appends to your display string variable. then call renpy.restart_interaction (if necessary).
4. in your screen, display the string variable in a container frame in a viewport
5. ...
6. profit
 
Last edited:
  • Like
Reactions: DiviDreamer