Hi guys, so I managed to create an "test.js" file.
In this JS file, I have a function "function go(){ var test = "message";}
My problem now is, I don't get it how can I show this content of my variable "test" ingame?
Example: Hello $test how are you today?
How can I print or show this variable which is in my plugin into my game?
Thanks in advance <3
How to include/show variables from Plugin into ingame?
● ARCHIVED · READ-ONLY
-
-
PHP:
function go(){ var test = "message"; return test;}; console.log(go()); -
@Jonforum he wants to show ingame, not in console
@Flicker789 you need to transfer the value into one of the existing game variables and then use the textcodes for variables in show text. -
This won't work because test only exists within the function, so as soon as you exit the function, the variable is gone.In this JS file, I have a function "function go(){ var test = "message";}
Instead you need a global variable, like this:
Code:By not writing "var" in front, the variable becomes global.function go() { test = "message"; }
Or better yet, since other plugins might also need a global test variable, do this:
Code:"MyPlugin" here is intended as a namespace. It's basically a name that you're certain no other plugin will use, so no other plugin will overwrite it.MyPlugin = {}; function go() { MyPlugin.test = "message"; }
In your case, you can use "Flicker789" instead of "MyPlugin". If you intend to share variables between your plugins, you can also do this:
Code:You get the idea.Flicker789 = Flicker789 || {}; // makes sure you don't overwrite it if it already exists Flicker789.MyAwesomePluginName = {}; function go() { Flicker789.MyAwesomePluginName.test = "message"; }
Next, in order to show the variable's value in a message window, you need to put the variable's value into an RMMV variable.
Use "Control Variables" -> "Set" -> "Script" -> "test" or "MyPlugin.test" (without the quote marks).
In the message window, you'd write:
Code:Assuming you stored test into variable 1.Hello \v[1] how are you today?
The easiest way to deal with this, however, is to reserve a variable for your plugin to use, then write directly into that variable:
Code:This writes "message" into variable 1, which you can then access with \v[1].function go() { $gameVariables[1] = "message"; } -
I understand but he got an answer depending on the time he put to properly format his issue.@Jonforum he wants to show ingame, not in console
@Flicker789 you need to transfer the value into one of the existing game variables and then use the textcodes for variables in show text.
If he wants a more detailed answer with a broader context, he has to reformat his question and give more details about his objective.
Can not read in people's minds. -
This won't work because test only exists within the function, so as soon as you exit the function, the variable is gone.
Instead you need a global variable, like this:
Code:By not writing "var" in front, the variable becomes global.function go() { test = "message"; }
Or better yet, since other plugins might also need a global test variable, do this:
Code:"MyPlugin" here is intended as a namespace. It's basically a name that you're certain no other plugin will use, so no other plugin will overwrite it.MyPlugin = {}; function go() { MyPlugin.test = "message"; }
In your case, you can use "Flicker789" instead of "MyPlugin". If you intend to share variables between your plugins, you can also do this:
Code:You get the idea.Flicker789 = Flicker789 || {}; // makes sure you don't overwrite it if it already exists Flicker789.MyAwesomePluginName = {}; function go() { Flicker789.MyAwesomePluginName.test = "message"; }
Next, in order to show the variable's value in a message window, you need to put the variable's value into an RMMV variable.
Use "Control Variables" -> "Set" -> "Script" -> "test" or "MyPlugin.test" (without the quote marks).
In the message window, you'd write:
Code:Assuming you stored test into variable 1.Hello \v[1] how are you today?
The easiest way to deal with this, however, is to reserve a variable for your plugin to use, then write directly into that variable:
Code:This writes "message" into variable 1, which you can then access with \v[1].function go() { $gameVariables[1] = "message"; }
This was a good explanation! Thank you so much <3