samspade
Member
I have arrays that hold arrays and when pulling out the sub arrays and modifying them inside of the step event (and other events) I found that I was experiencing the copy behavior which happens when you pass an array by reference to a script.
Simple example to illustrate:
If you run this in the debugger, you can see that sub_a and sub_b are the same as the internal arrays when first copied but as soon as you modify the values, the array they point to changes - so you are not modifying the internal array.
However, if you do this:
Then you do modify the internal arrays. This will also happen with instance and global scoping.
This is expected behavior if in a script, but in reading the manual I don't see anywhere where it says this will happen inside of a event.
Is this expected behavior for events? And if so is it in the manual and I'm just missing it?
Simple example to illustrate:
Code:
///step event (or other event)
array = [[0, 1], ["hello", "world"]];
var sub_a = array[0];
var sub_b = array[1];
sub_a[0] = 1;
sub_a[1] += 1;
sub_b[0] = "goodbye";
However, if you do this:
Code:
///step event (or other event)
array = [[0, 1], ["hello", "world"]];
var sub_a = array[0];
var sub_b = array[1];
sub_a[@ 0] = 1;
sub_a[@ 1] += 1;
sub_b[@ 0] = "goodbye";
This is expected behavior if in a script, but in reading the manual I don't see anywhere where it says this will happen inside of a event.
Is this expected behavior for events? And if so is it in the manual and I'm just missing it?