How to include/show variables from Plugin into ingame?

Flicker789

Warper
Member
Joined
Mar 29, 2018
Messages
2
Reaction score
1
First Language
English
Primarily Uses
RMMV
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
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
PHP:
function go(){ var test = "message"; return test;};
console.log(go());
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
@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.
 

Nolonar

Veteran
Veteran
Joined
Feb 18, 2018
Messages
163
Reaction score
243
First Language
French, German
Primarily Uses
RMMZ
In this JS file, I have a function "function go(){ var test = "message";}
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:
function go() {
    test = "message";
}
By not writing "var" in front, the variable becomes global.

Or better yet, since other plugins might also need a global test variable, do this:
Code:
MyPlugin = {};
function go() {
    MyPlugin.test = "message";
}
"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.
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:
Flicker789 = Flicker789 || {}; // makes sure you don't overwrite it if it already exists
Flicker789.MyAwesomePluginName = {};

function go() {
    Flicker789.MyAwesomePluginName.test = "message";
}
You get the idea.


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:
Hello \v[1] how are you today?
Assuming you stored test into variable 1.


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:
function go() {
    $gameVariables[1] = "message";
}
This writes "message" into variable 1, which you can then access with \v[1].
 
Last edited:

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
@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.
I understand but he got an answer depending on the time he put to properly format his issue.

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.
 

Flicker789

Warper
Member
Joined
Mar 29, 2018
Messages
2
Reaction score
1
First Language
English
Primarily Uses
RMMV
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:
function go() {
    test = "message";
}
By not writing "var" in front, the variable becomes global.

Or better yet, since other plugins might also need a global test variable, do this:
Code:
MyPlugin = {};
function go() {
    MyPlugin.test = "message";
}
"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.
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:
Flicker789 = Flicker789 || {}; // makes sure you don't overwrite it if it already exists
Flicker789.MyAwesomePluginName = {};

function go() {
    Flicker789.MyAwesomePluginName.test = "message";
}
You get the idea.


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:
Hello \v[1] how are you today?
Assuming you stored test into variable 1.


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:
function go() {
    $gameVariables[1] = "message";
}
This writes "message" into variable 1, which you can then access with \v[1].

This was a good explanation! Thank you so much <3
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,863
Messages
1,017,053
Members
137,571
Latest member
grr
Top