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

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!
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.
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.
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.
@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.
Awesome, thank you! This has all been very helpful 🙂

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.

Original thread: https://forums.rpgmakerweb.com/threads/solved-need-help-with-storing-values-within-an-array-variable.131778/