MV Get variable value into Javascript

Hello, there's a plugin about input name. There's a description text "Input a name" and "Press ENTER when ready" shown like this

Screenshot_20221223_143124.png


You can change through parameter from plugin manager

1671781838346.png


I want to know about this

Screenshot_20221223_142511.png


In short, I want set a string on variable and from Javascript call that variable

I tried something like this
1671781491273.png


But it gives me an error at start of game
1671781533090.png


This will make a default input like this
1671781899525.png


Is it possible to do that? If it is, which part did I do wrong?
Your code screenshot doesn't provide line numbers, so we can't see where the error is based on your error trace.

However:
The game variables don't exist before the game starts, so if this is in a portion of the plugin that's loading the plugin parameters, this won't work.

Also, a variable is not going to be null unless you intentionally set it to that.

Thirdly, there's no reason to do String($gameVariables.value(3)) - if the contents of that variable are set to be a string, it's a string.

It might help if you explained what you're trying to accomplish and why.
if you want to change display message through variable
you can also try to change line 445 to something like this:
JavaScript:
        Window_NameExplanation.prototype.refresh = function() {
            this.contents.clear();
            let text = eval(_displayMessage);
            let text2 = eval(_displayMessage);
            this.drawText(text, -10, 0, this.windowWidth(), 'center');
            this.drawText(text2, -10, this.lineHeight(), this.windowWidth(), 'center');
        };
    }

than on the display message and disaply message 2, you can set

$gameVariables.value(3)

than control that inside the game anywhere you like.
I would suggest to use 2 different variables for line 1 and line 2.

otherwise, more code need to change a bit to allow "enter" for a new string
like "\n" for the splitting the text.
Your code screenshot doesn't provide line numbers, so we can't see where the error is based on your error trace.

However:
The game variables don't exist before the game starts, so if this is in a portion of the plugin that's loading the plugin parameters, this won't work.

Also, a variable is not going to be null unless you intentionally set it to that.

Sorry I forgot to provide the line error, this 240

1671835921994.png


This 528
1671835827164.png


About null, I grab a default value that I set on plugin manager just in case if I don't put any value on that variable
Thirdly, there's no reason to do String($gameVariables.value(3)) - if the contents of that variable are set to be a string, it's a string.
I was try without and with that, but you've got a point. I think that's redundant
It might help if you explained what you're trying to accomplish and why.
So I want to make a puzzle game like Spotlight: Room Escape (Android game). Some of items are locked on treasure and need to unlocked using password. The password input using this plugin and adding some condition, which is work well like this

1671836291736.png

But, there's a problem. I want on start of the game that a player input their name first. Which the description text are shown same as I want to put a password

And then came up with idea that grabbing variable value into that plugin. So I just use that variable to change description text

if you want to change display message through variable
you can also try to change line 445 to something like this:
JavaScript:
        Window_NameExplanation.prototype.refresh = function() {
            this.contents.clear();
            let text = eval(_displayMessage);
            let text2 = eval(_displayMessage);
            this.drawText(text, -10, 0, this.windowWidth(), 'center');
            this.drawText(text2, -10, this.lineHeight(), this.windowWidth(), 'center');
        };
    }

than on the display message and disaply message 2, you can set

$gameVariables.value(3)

than control that inside the game anywhere you like.
I would suggest to use 2 different variables for line 1 and line 2.

otherwise, more code need to change a bit to allow "enter" for a new string
like "\n" for the splitting the text.

I tried to add like this with console.log
1671838121612.png

1671838433481.png


But it gives me an error and show about $gameVariables
1671838151602.png

I think this problem just like @ATT_Turan mention
The game variables don't exist before the game starts, so if this is in a portion of the plugin that's loading the plugin parameters, this won't work.
Is there anything on plugin to change into load variable throughout game play?
So I want to make a puzzle game like Spotlight: Room Escape (Android game). Some of items are locked on treasure and need to unlocked using password. The password input using this plugin and adding some condition, which is work well like this
But, there's a problem. I want on start of the game that a player input their name first. Which the description text are shown same as I want to put a password
Okay...I had this fairly long post written out, and I finally realized: you're trying to change the words that say "Input a name."

I still don't get why you're trying to approach it using game variables. You described only two different purposes for the window - to input a name and to input a password. Are there other things you use this for?

If there are, we can stuff a variable in there, but I would just do this. Make the actual plugin parameter say "Input password" - then, starting on line 445:
Code:
        Window_NameExplanation.prototype.refresh = function() {
            this.contents.clear();
            if (!$gameSwitches.value(1)) _.displayMessage="Input name";
            this.drawText(_.displayMessage, -10, 0, this.windowWidth(), 'center');
            this.drawText(_.displayMessage2, -10, this.lineHeight(), this.windowWidth(), 'center');
        };

That way at the beginning of the game, when you call the screen the first time, it will say "Input name" (or whatever you edit that text to say). Then, after the player chooses their name, turn game switch 1 ON and for the rest of the game it will say "Input password" (or whatever you typed in the parameter).

Edit the text to say exactly what you want, change the number 1 to be an unused switch.
If there are, we can stuff a variable in there, but I would just do this. Make the actual plugin parameter say "Input password" - then, starting on line 445:
Code:
        Window_NameExplanation.prototype.refresh = function() {
            this.contents.clear();
            if (!$gameSwitches.value(1)) _.displayMessage="Input name";
            this.drawText(_.displayMessage, -10, 0, this.windowWidth(), 'center');
            this.drawText(_.displayMessage2, -10, this.lineHeight(), this.windowWidth(), 'center');
        };

That way at the beginning of the game, when you call the screen the first time, it will say "Input name" (or whatever you edit that text to say). Then, after the player chooses their name, turn game switch 1 ON and for the rest of the game it will say "Input password" (or whatever you typed in the parameter).

Edit the text to say exactly what you want, change the number 1 to be an unused switch.
I didn't thought about this before. I tried this and it work!
Also, I try use @ShadowDragon method again from your idea, it works perfectly! I think I put a wrong place of code before where $gameVariables still null (Not yet to be set because start of the game)

So using switch could be like this:
1671873259823.png


While variable could be like this:
1671873398832.png

Okay...I had this fairly long post written out, and I finally realized: you're trying to change the words that say "Input a name."

I still don't get why you're trying to approach it using game variables. You described only two different purposes for the window - to input a name and to input a password. Are there other things you use this for?
I don't have anything in mind yet. But it might useful on future if I need to use variable
With variable, I can change any text what I want through game engine. Using switch will make a hard code (You need to set up from JS file again to make a change and this could make less efficient)

I think I should learn deeper about JS in RMMV. Thank you for your help @ATT_Turan @ShadowDragon ! My question has been answered

Original thread: https://forums.rpgmakerweb.com/threads/get-variable-value-into-javascript.153472/