- Joined
- Jan 12, 2016
- Messages
- 22
- Reaction score
- 2
- First Language
- English
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.
*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]));
Last edited by a moderator:

