GML Issue with arrays

S

SiR2104

Guest
Hello, very strange bug! I dont know whats wrong(
Code:
Code:
w = 22;
h = 22;
grid = [];

var rm;

for (var i = 0; i<w; i++) {
    for (var j = 0; j<h; j++) {
        if i == 0 or i == w-1 or j == 0 or j == h-1 {
            rm[0] = noone;
            rm[1] = i;
            rm[2] = j;
            grid[i, j] = rm;
        }
        else {
            rm[0] = room_duplicate(rm_default);
            rm[1] = i;
            rm[2] = j;
            grid[i, j] = rm;
            show_debug_message("c: "+string(grid[i,j]))
            show_debug_message("u: "+string(grid[i,j-1]))
        }
    }   
}
In out same values:

Debug:
Code:
c: { { 399,20,19 },  }
u: { { 399,20,19 },  }
And if i change value to show_debug_message("u: "+string(grid[i-1,j-1])) - Nothing change.
 
I

icuurd12b42

Guest
try
rm = [
room_duplicate(rm_default),
i,
j
];

every iteration, that should create a new array for each entry instead of reusing the same one over and over
 
Top