Problem: Collecting variables into one

Alexaaskov

Somewhat New
Member
Joined
Jun 8, 2018
Messages
2
Reaction score
0
First Language
Danish
Primarily Uses
RMXP
So I have been tinkering with variables in RMXP and it hasn't exactly been easy. Most forums that helps with variable-related problems doesn't use RMXP. I have been trying to add the content of one variable to another variable.

I don't mean something like:
Var(3) = Var(1) + Var(2)

But something like:
Var(1) = [1, 2, 3] & Var(2) = [4, 5, 6]
Var(3) = [Var(1), Var(2)] = [1, 2, 3, 4, 5, 6]

When I try this my third variable becomes [123,456] instead. A forum on "Support/JavaScript Boards/Learning JavaScript" posted by Llareian was talking about this problem and came up with an solution. I tried to modify the solution for RMXP, but I don't seem to have the functions they use. Any suggestions are appreciated.

Solution for Llareian:
if ( !$gameVariables.value(15) ) { $gameVariables.setValue(15, []) };
$gameVariables.value(15).push( $gameVariables.value(16) );
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,025
Reaction score
7,026
First Language
German
Primarily Uses
RMMV
this can't be done directly due to the way variables are stored.

By default each variable can hold only a single value. you can redefine that to a different form of a variable (like the array variable you propose), but then you need to access that variable as an array as well - and that usually requires more steps.
for example your first idea needs to be split into first a redefinition of var 1 into an array variable, then three steps adding the content of var 2 to each elements of the array in var 1.
that simply cannot be done in a single command.

and in all cases XP uses a ruby-variant called RGSS - you can't use javascript code in XP. Those are two entirely different programming languages.
 

Alexaaskov

Somewhat New
Member
Joined
Jun 8, 2018
Messages
2
Reaction score
0
First Language
Danish
Primarily Uses
RMXP
Thank you for the respons. I hadn't found out exactly what the coding language was called in RMXP, so that helps.
It is unfortunate that there is no simple function to do this. I will try and make something with loops, so I don't have to write a line of code each time I want to add to my variable.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,141
Reaction score
12,416
First Language
English
Primarily Uses
RMMV
$gameVariables.value(15)

This is also the MV way of using variables. In RMXP, it is $game_variables[15] = ...
There is no .value and .setValue - in XP you are accessing the variables array/data directly, not via functions (kind of)
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
559
Reaction score
272
First Language
German
Primarily Uses
Hey there,

If both of your variables var1 and var2 hold arrays, you can actually combine them using the plus sign:
Code:
var1 = [1, 2, 3]
var2 = [4, 5, 6]
var3 = var1 + var2  # => [1, 2, 3, 4, 5, 6]
Don't know if it helps here, but for an overview/documentation of the standard library you can look here (this one is for Ruby 1.8.7 though. RMXP uses 1.8.1, which is unfortunately not documented there, but almost everything is still applicable).

$game_variables allows you to access the set of variables also used in events. They come in handy if you want an easy way to save something with the rest of the savestate for example, and can be treated like other variables apart from that.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Managed to find a way to hang a bed cover over my window. So no more being toasted alive in the afternoon!:kaoswt2:
So, uh, has anyone tried buying any resources from KokoroReflections? Because I've been looking for a 'buy' button on the site for like 10 minutes now and can't find one.
Any also thought it's too cringy to put the word "and you" in your credit as a special thanks?
Cause that's what I thought...
Everyone in the US right now: Please stay safe.
Symphony Celestia: Prophecy of the Falling Stars RPG Maker music pack WIP. Symphony Celestia is a new series that focuses on symphonic and orchestrated music to tell a story. Each story will include compositions that make up that story from beginning to end. Themes include: Battles, adventures, character themes, etc. Below is a video preview to the first story.

Forum statistics

Threads
97,980
Messages
948,318
Members
129,242
Latest member
Kelevra069
Top