A function that lets me substitute several variables at once.

I have an event where based on a very long string of conditions that changes the values of two variables based on other variable.
Example:
If: Main variable = 29
Control Variable: Variable X = 2
Control Variable: Variable Y = 9

If: Main variable = 30
Control Variable: Variable X = 3
Control Variable: Variable Y = 0

If: Main variable = 31
Control Variable: Variable X = 3
Control Variable: Variable Y = 1

And this goes on from 0 to 199. So it is a bunch of conditions and variables.

I want to create a copy of this long string and only substitute those 3 variables as fast as I can. Doing it manually one by one would take toooo long since I want to do at least 16 different events in this way. Is there a way to just substitute the variables?
Example:
If: Main variable = 29
Control Variable: Variable X = 2
Control Variable: Variable Y = 9

And just substitute "Main variable" to "Main variable 2", substitute "Variable X" to " Variable X 2" and "Variable Y" to " Variable Y 2"

So I don't need to change the number, just the variables it self!
What variable number is "Matematica"? Replace 10 with that variable number

Code:
var stringVar = $gameVariables.value(10).toString();
$gameVariables.setValue(89, stringVar.charAt(stringVar.length-1));
$gameVariables.setValue(90, stringVar.charAt(stringVar.length-2));
ninja'd by AquaEcho

here is what I used:
JavaScript:
◆Control Variables:#0004 = 198
◆Control Variables:#0005 = Number(String($gameVariables.value(4)).slice(-2)[0])
◆Control Variables:#0006 = Number(String($gameVariables.value(4)).slice(-1)[0])
◆Text:None, Window, Bottom
:    :\v[4]
:    :\v[5]
:    :\v[6]

Spoiler
scan.png

scan2.png
What variable number is "Matematica"? Replace 10 with that variable number

Code:
var stringVar = $gameVariables.value(10).toString();
$gameVariables.setValue(89, stringVar.charAt(stringVar.length-1));
$gameVariables.setValue(90, stringVar.charAt(stringVar.length-2));
Was I supposed to put this code as a script call before the rest of the event? Sorry, I'm still really bad at coding stuff so I don't get it....
ninja'd by AquaEcho

here is what I used:
JavaScript:
◆Control Variables:#0004 = 198
◆Control Variables:#0005 = Number(String($gameVariables.value(4)).slice(-2)[0])
◆Control Variables:#0006 = Number(String($gameVariables.value(4)).slice(-1)[0])
◆Text:None, Window, Bottom
:    :\v[4]
:    :\v[5]
:    :\v[6]

It's working almost perfectly!!!! God, this will spare me soooo much work in a dozen of different aspects of the game, you basically saved my life! The only tiny problem is that when the value of the first variable is smaller than 10, both variables become the same number! at least in my testing. Of course, I can easily fix this using a conditional branch with >10 = 0. But just so I let you know ! Thanks for the big help, Really!!
Was I supposed to put this code as a script call before the rest of the event? Sorry, I'm still really bad at coding stuff so I don't get it....
It's a script call that simply sets contol variable 89 and 90 to the second to the last digit and last digit of the number in variable 10. But if bass' scripts work then use those, it's just two ways to the same outcome.
I see. My assumption was that you only wanted the 1s and 10s digits. Yes, you can do a conditional branch and force it to be 0 if it is less than 10.

Glad it is working the way you want.

What AquaEcho had should work too, you just need to use the correct variables for your game.
You could also use modulo and simple mathematical operations, for example:

◆Control Variables:#0004 = 198
◆Control Variables:#0005 = Math.floor(($gameVariables.value(4)% 100) / 10);
◆Control Variables:#0006 = $gameVariables.value(4)%10


In this way, you will always get the tens and ones of your 3-digit number. You don't even need a conditional check. You could place the code for storing the variables in a common event and call it whenever needed, without rewriting the code
And just to supplement what @ISC said, RPG Maker has modulo built into Control Variables, and division automatically discards decimals. So you can do what he showed you without using script calls.

Original thread: https://forums.rpgmakerweb.com/threads/a-function-that-lets-me-substitute-several-variables-at-once.172088/