Make "Show Text" dynamically shows a changing text

Hi everyone, I'm now working on a project that uses ChatGPT in RMMZ. I use a game variable (say \V[1]) to store a response returned by ChatGPT. As ChatGPT provides streaming option to return the response words one by one, the variable \V[1] is expected to change frequently.
I want the "Show Text" event to display the updated \V[1] everytime when the \V[1] changes, till a "response end" signal is received and \V[1] becomes determinstic. I could configure some switches to implement these conditionals, but what confused me most is the Show Text event. When use this event, the message window won't continue or disappear before we click left mouse or something else. This means I cannot use loop to repeatedly show the message window and automatically update the changed text \V[1].
So I'm wondering whether I could realize this dynamic text function just using some built-in events in RMMZ, or whether I have to do some plugin work to implement it (sorry, I'm very new to RMMZ!). Thanks!

Note: I've known a plugin ChatGPT_APIMZ made by kotonoha*. It did a great work, and I noticed that it directly draw an HTML element as the customized message window in the game. What I'm working on is a little different from directly calling OpenAI's API in the plugin, so I'm here to find some built-in solutions 🙂
Not sure if this is what you're looking for but there's a control character:
\^
that you can use if you want the text message to close without player input.
Not sure if this is what you're looking for but there's a control character:
\^
that you can use if you want the text message to close without player input.
Thank you werzaque, I added the character \^ and get some positive results. Currently I used the following logic: repeatly raise "show text" event in a loop until the message \V[1] becomes determinstic, and in "show text" I typed \>\V[1]\^ to immediately show the text and continue the loop without player input.

Now I meet another problem: the message in \V[1] contains line break \n, and in this case the \> control character can only work in the first line. When it comes to multiple lines the message window show like this: (what I want is the immediate display of all lines)

无标题视频——使用Clipchamp制作.gif


Any solutions?

P.S. I'm now checking the Instant Text plugin, maybe it could solve that
(what I want is the immediate display of all lines)
If you mouse over the Show Text text box, it lists escape codes you can use. \> prints that line immediately.
If you mouse over the Show Text text box, it lists escape codes you can use. \> prints that line immediately.
my bad, I means the \> here. Edited!
the \^ control character can only work in the first line

so my problem is \> can only work on the first line. I'm looking for some solutions on how to directly insert this command character in the variable now
my bad, I means the \> here. Edited!


so my problem is \> can only work on the first line. I'm looking for some solutions on how to directly insert this command character in the variable now
Found it in here! After adding \x1b> after the \n in the variable, it can finally show multiple lines immediately.
It's fine, \v[x] is a "convert" code (pre-message) and \. is a "process" code (mid-message). You just need to use \x1b instead of \\, since the default code pre-converts all backslashes to the \x1b escape character. E.g. Control Variables > Script:
Code:
"Hi! \x1b.How's things?"
Thanks everyone here kindly giving the solutions 😍
After adding \x1b> after the \n in the variable, it can finally show multiple lines immediately.
Frustratingly, the command character in the variable string seems not having equal performance to that in the "show text" input. When the loop executes, lines with \> display normally, but lines with \x1b> in the variable keep flashing:

无标题视频——使用Clipchamp制作 (1).gif


In "Show Text" input: \>\V[1]\^
In variable \V[1]: veryveryveryveryveryveryv\n\x1b>eryveryveryveryveryverylongtext111\n\x1b>222

This problem may have beyond the original thread topic, but I still hope a perfect solution to display all text immediately in the looping scenario 🙂
Frustratingly, the command character in the variable string seems not having equal performance to that in the "show text" input. When the loop executes, lines with \> display normally, but lines with \x1b> in the variable keep flashing:

View attachment 278077

In "Show Text" input: \>\V[1]\^
In variable \V[1]: veryveryveryveryveryveryv\n\x1b>eryveryveryveryveryverylongtext111\n\x1b>222

This problem may have beyond the original thread topic, but I still hope a perfect solution to display all text immediately in the looping scenario 🙂
That's because while every line is being shown instantly... there is still a delay between each line.
There's a simple fix for it, which I actually have in my own game as well - disable resetting _lineShowFast on the end of a line. This does mean you have to use \< at the end of the line if you ever want vanilla behaviour, but otherwise this works perfectly fine for me.

JavaScript:
Window_Message.prototype.processNewLine = function (textState) {
    Window_Base.prototype.processNewLine.call(this, textState);
    if (this.needsNewPage(textState)) {
        this.startPause();
    }
};
disable resetting _lineShowFast on the end of a line
I add the js code in my own plugin, sadly the text is still flashing 🙁
Delays exist, and the flashing becomes more evident (delay time is longer) as the number of lines increases.
I add the js code in my own plugin, sadly the text is still flashing 🙁
Delays exist, and the flashing becomes more evident (delay time is longer) as the number of lines increases.

To clarify, is that with the plugin that changes the variable dynamically, or just a regular loop? If the latter, can you show the entire event that handles it? This does work for me, so there might be something there that you're doing differently.
with the plugin that changes the variable dynamically
Yes, the variable is dynamically changed in the plugin by $gameVariables.setValue().

To make more concise, my plugin builds a socket and listen to certain socketIO events from the server. When server sends a text to the plugin, a switch "responseReceived" is on, and it sets the variable \V[2] with the text like "something\n\x1b>something\n\x1b>some". The server continues to stream the text, until it tells the plugin the text is complete, and the plugin set the switch "responseEnd" off.

On the game event side, it looks like this:

1697195140414.png
Have you tried without \x1b>? I feel like using that and my solution together could potentially conflict.
If that doesn't help, try doing the same thing but without the plugin (so that everything relevant is visible in the event) and see if the problem persists there.
Have you tried without \x1b>? I feel like using that and my solution together could potentially conflict.
If that doesn't help, try doing the same thing but without the plugin (so that everything relevant is visible in the event) and see if the problem persists there.
Maybe I find the problem... it's not \x1b>, but the place of javascript codes. I put your code in my plugin:

(() => { const responseRecievedSwitchID = Number(pluginParameters["ResponseRecievedSwitchID"]) || 1; // some other parameter init settings // js code to stop text flashing const _Window_Message_processNewLine = Window_Message.prototype.processNewLine; Window_Message.prototype.processNewLine = function (textState) { _Window_Message_processNewLine.call(this, textState); if (this.needsNewPage(textState)) { this.startPause(); } }; PluginManager.registerCommand(pluginName, "raise_dialogue", args => { // my plugin commands ... } })()

This caused the problem I mentioned before (still flashing). But when I press F8 to activate in-game console and run your code, the text goes smoothly.

Should I put that js code in the "Script" event to make it work properly?
Should I put that js code in the "Script" event to make it work properly?
Ah, that seems simple - in a plugin lower down in your plugin list. At the bottom should work, but below anything else that messes with messages should be fine.
This is likely because something else is overwriting that change, so it need to happen later.
Ah, that seems simple - in a plugin lower down in your plugin list. At the bottom should work, but below anything else that messes with messages should be fine.
omg the code suddenly cannot work even I put the plugin order back to the before...

Anyway I found a brute force solution, directly copy the function from rmmz source and put it in my plugin:

JavaScript:
    const _Window_Message_processNewLine = Window_Message.prototype.processNewLine;
    Window_Message.prototype.processNewLine = function (textState) {
        Window_Base.prototype.processNewLine.call(this, textState);
        // this._lineShowFast = false;
        if (this.needsNewPage(textState)) {
            this.startPause();
        }
    };

Currently dont know what negative effects may occur, but this time it just works fine :oops:
Currently dont know what negative effects may occur, but this time it just works fine :oops:
In general overwriting a function instead of aliasing it tends to be worse for plugin compatibility, since it completely erases any changes done by other plugins. But it looks like that's actually a good thing in this case, since I'm guessing the problem was that another plugin was making a change that prevented this from working.
So if the messages are still working fine you shouldn't need to worry about that too much. Just keep in mind that if you ever run into a problem of a plugin that modifies messages not working, it might be because of that.

Original thread: https://forums.rpgmakerweb.com/threads/make-show-text-dynamically-shows-a-changing-text.161407/