RMMZ [Solved] Need Help with Storing Values within an Array Variable

Status
Not open for further replies.

Speedvore

RPG Making since RM95!
Veteran
Joined
Oct 3, 2015
Messages
31
Reaction score
10
First Language
English
Primarily Uses
RMMZ
I'm working on making a custom battle system that uses character friendship points to determine various mechanics. I'm currently having trouble efficiently tracking these friendship stats between characters. The game I'm working on is planned to have tons of playable characters, much like Chrono Cross or Suikoden, so right now I'm at ~55 playable characters.

My initial plan was to create a variable for each character's relation to each other (i.e. Character 1 & Character 2's relation, Character 2 & Character 3, Character 2 & Character 3, etc.). However, I realized that to do this with such a large cast of characters, that would require over 1,000 different variables to track this data. I know RPG Maker limits to 5,000 variables, so while it's doable, it still would require a ton of variables to keep track of for this one mechanic.

I've been looking into using arrays, as that seems like it could be the best solution, but I'm stumped on how to go this route, since I'm still a beginner when it comes to JavaScript and programming in general.

Here's what I'm thinking so far:

This array variable will track the playable character names (5 names in there currently):
JavaScript:
$gameVariables.setValue(61,  ["Gair", "Pubby", "Ralphie", "Zandra", "Scott"]);

Then, this is where I'm stumped. I was thinking I could make a single variable for each character, and store multiple values within that variable (according to the original order of the characters), and track their friendship levels in there. But I honestly am not too sure if that's possible.

This is where I'm at with this part, in printing the name of that value (the second name in this case) within an array, but not sure where to move next:
JavaScript:
$gameVariables.setValue(62, $gameVariables.value(61)[1]);

So if anyone has any ideas on this, that would be super helpful. Thanks!
 

Hyouryuu-Na

Very very lazy
Veteran
Joined
Jun 15, 2017
Messages
1,073
Reaction score
2,541
First Language
Not English
Primarily Uses
RMMV
I'm confused about what you're trying to do here:
$gameVariables.setValue(62, $gameVariables.value(61)[1]);
Let's say you want to make variable 62 for Pubby and their friendship level with the other chars. Then why do you need to assign the name to this? Can't you just go-
$gameVariables.setValue(62, [0,0,0,0,0]) //Assigning a spot for each character's the friendship value
$gameVariables.value(62)[0]=10 //Setting 10 as Gair and Pubby's friendship value
$gameVariables.value(62)[1]=0 //cause pubby can't be friends with themselves. Could leave it as is. It's //always 0
$gameVariables.value(62)[2]=15 //Setting 15 as Ralphie and Pubby's friendship value
etc. etc.
 

Speedvore

RPG Making since RM95!
Veteran
Joined
Oct 3, 2015
Messages
31
Reaction score
10
First Language
English
Primarily Uses
RMMZ
Let's say you want to make variable 62 for Pubby and their friendship level with the other chars. Then why do you need to assign the name to this? Can't you just go-
$gameVariables.setValue(62, [0,0,0,0,0]) //Assigning a spot for each character's the friendship value
$gameVariables.value(62)[0]=10 //Setting 10 as Gair and Pubby's friendship value

Thank you so much! I have a hard time fully grasping arrays since I'm still learning, but with the way you laid it out here, that makes a lot of sense and is exactly what I needed. This really clarifies things a lot, and I know how I can use this system now for my game, thank you!

Going off of this, is there a way to easily reference an array value in text form? I know you can print the variable value with \v[62], but when I print the array variable, it will print all of the values within the array.

I'm wondering if there's a text code/method to print the specific array value, so I can refer to the friendship level in a Show Text event.
 

Zero_G

Veteran
Veteran
Joined
Mar 28, 2020
Messages
57
Reaction score
38
First Language
English
Primarily Uses
RMVXA
Be careful, because the game engine is not designed to store arrays in its game variables, and that will probably cause problems down the line.

Best you can do without modifying the game code to allow arrays in game variables would be to reserve five variables for each character instead of one variable with an array of five.
 

Hyouryuu-Na

Very very lazy
Veteran
Joined
Jun 15, 2017
Messages
1,073
Reaction score
2,541
First Language
Not English
Primarily Uses
RMMV
@Speedvore You can either store it in a new variable like $gameVariables.setValue(63, $gameVariables.value(62)[0]) and then call it with \v[63] or if you don't want to do that, show the message from script call:
$gameMessage.addText("Pubby and Gair's frisndship level is now "+$gameVariables.value(62)[0]+".")
Note: I'm referencing MV's script call for the show text function. You should check out MZ's one. It could be different, I'm not sure.
--------
Also just pointing out for anyone wondering, using arrays as default game variables will not cause problems. The MV script call list actually has a segment about using arrays. This list has been made by people who have vast knowledge about RPG Maker so if they say you can use arrays, definitely you can use them without thinking twice.
 
Last edited:

Speedvore

RPG Making since RM95!
Veteran
Joined
Oct 3, 2015
Messages
31
Reaction score
10
First Language
English
Primarily Uses
RMMZ
Awesome, thank you! This has all been very helpful :)
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
8,137
Reaction score
5,375
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

I have an idea, I am making low polygon 3D resources for a package in itch. but it occurred to me that I could export these as images and make MV / MZ compatible tilesets. What do you think of this?
I hate seeing threads where less-experienced user's ask for an opinion of their project, and the thread is full of negative feedback by others who are clearly not the target audience. I feel bad for the OP, and I hope they understand that no game can appeal to everyone. :frown:
Hm, just found out I can't use loops, yay.
-Ele
I just wanna Covid to be over and I have my normal life back... Feeling so bad these days, what can I do?

Forum statistics

Threads
109,074
Messages
1,041,867
Members
141,571
Latest member
1a23z11
Top