How can i to set variable using variable name in RPG Maker MV?

Mogumogu09

Warper
Member
Joined
Nov 27, 2019
Messages
4
Reaction score
0
First Language
Indonesian
Primarily Uses
RMMV
Usually to set variable value i use this code:

$gameVariables.setValue(3, 4);

number 3 is id variable and 4 is value of 3 in RPG Maker MV.
can i set variable not by using id variable but by using Variable name in RPG Maker MV?
i already try this:

$gameVariables.setValue(idItem, 4);

but idItem's value doesn't change.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
No, you have to use the variable id.

What would happen if you tried to do that, and you had more than one variable with the same name?

You could ask someone to write a plugin for it, but it would only work via plugin or script commands. Any event commands or event/troop conditions would still have to use the variable id. And having a plugin to look up a name to find the id, and then change the variable with that id, would add extra processing, so you'd lose a bit of efficiency.


You could do something like this:
Code:
var idItem = 3;
$gameVariables.setValue(idItem, 4);
but what's the point? You still have to define that idItem is variable 3.
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
954
Reaction score
520
First Language
Javascript
Primarily Uses
RMMZ
can i set variable not by using id variable but by using Variable name in RPG Maker MV?
Sure can :) It's like this :cutesmile:
Code:
$gameVariables.setValue($dataSystem['variables'].indexOf('itemId'), 4);
Created a plugin for you :)
VarByName Plugin: Click to Download

Script Calls:
Code:
setVarByName(name, value, occurrence);
getVarByName(name, occurrence);
Examples:
Code:
setVarByName('idItem', 1); // sets the value first occurrence of "idItem" equal to 1
getVarByName('idItem'); // returns the value first occurrence of "idItem"
setVarByName('idItem', 5, 2); // sets second occurrence of "idItem" equal to 5

v0.2 Now you can name multiple variables the same name :)
v0.2+ Script Calls:
Code:
setVarByName('idItem', 1, 2);
getVarByName('idItem', 2);
That will set to find the second occurrence of the named variable :)
Code:
setVarByName('idItem', 2, 6);
getVarByName('idItem', 6);
That will set to find the sixth occurrence of the named variable :)

Essentially this would work kind of like an array of its own.

Extra Example:
lol... soo... Ok this might seem a bit crazy but stay with me here :blink::cutesmile::popcorn:
Code:
// This sets the third occurrence or "idItem" to the sum of the first and second occurrence of "idItem"
setVarByName('idItem', "getVarByName('idItem', 1)+getVarByName('idItem', 2)", 3);

Let me know how it goes, hope it works the way you need :)
 
Last edited:

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

Latest Threads

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,867
Messages
1,017,062
Members
137,575
Latest member
akekaphol101
Top