Why do you want to copy it? Maybe there’s a way to do what you want to do without copying it.
You might be able to do it with the Array Tools extension. If not you could properly copy it through JSON. Convert array to a JSON string and then from the JSON string back to a variable.
Shouldn’t this be supported by the engine?
I tried method two using extension before asking and it doesn’t work.
I will try a new project and see how it goes.
Thanks.
Can you show us the events? I use the array tools extension to copy arrays and I haven’t had any problems.
However, you don’t really need to copy the array in order to read from it, as long as the size of the nested arrays is all the same you can just store the indexes as a variable and increase them appropriately.
I just tested my methods again. I even added another array level and it worked. Are you using scene or global variables? With the recent changes to GD, it shouldn’t matter as much. I tested both methods with scene and global variables. The extension uses different functions for global and scene variables and both arrays seem to need to both be either scene or global.
This is what I used. I added a button to trigger the for each child so I could check values before and after and do other tests.
I didn’t use both methods at the same time. I disabled one of them to test the other.
Variables are easy to “break” or modify unexpectedly. GD does some things to prevent crashes that can sometimes cause unexpected things to happen. Like creating variables if they don’t exist. It can be safer to check if arrays and structures exist before trying to access them. Otherwise, if they’re not there the 1st time then there might be an empty variable there the 2nd time.
A variable can exist but it might have the right children names or indexes. So, while Array1[0] could exist Array1[10] might not.
You might need to clear the target array first depending on your needs. If needed you can use for each child starting with any child not just the top level.