RPG Maker Forums

I am having some troubles with using arrays within arrays.  I thought I had it figured out, but noticed when trying to change one, it will change the entire array.  Below is just a test I was doing but it doesn't do what I thought it should.  The original messages are all 0, which is what I had thought, but when I try to change 0,0  it also changes 1,0.    Would anyone be able to tell me what I'm doing wrong?


*Edit*


It must be an issue with making the array using a variable, because when I manually make the array with $gameSystem.testarray = [[0,0],[0,0]];   then I don't have any problems changing just one.  Is there some other way to do it or am I doing that incorrectly?


*Edit #2*


I'm pretty sure I figured out how to make this work for me as I haven't had any errors yet.  Let me know what you think.

Code:
$gameSystem.sellableitem = [];
for (var a=0;a<5;a++) { 
 $gameSystem.sellableitem[a] = [];
 for (var b=0;b<10;b++) {
  $gameSystem.sellableitem[a][b] = [];
  for (var c=0;c<20;c++) {
    $gameSystem.sellableitem[a][b][c] = [];
  }
 }
}


Code:
var t = [0,0];

$gameSystem.testarray = [t,t];

$gameMessage.add(String($gameSystem.testarray[0][0]));

$gameMessage.add(String($gameSystem.testarray[0][1]));

$gameMessage.add(String($gameSystem.testarray[1][0]));

$gameMessage.add(String($gameSystem.testarray[1][1]));

$gameSystem.testarray[0][0] = 1;

$gameMessage.add(String($gameSystem.testarray[0][0]));

$gameMessage.add(String($gameSystem.testarray[0][1]));

$gameMessage.add(String($gameSystem.testarray[1][0]));

$gameMessage.add(String($gameSystem.testarray[1][1]));

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,038
Messages
1,018,466
Members
137,821
Latest member
Capterson
Top