I'm not sure if this is a Java Script question or an MZ Support question. But I discovered an unexpected behavior with Arrays.
I wanted to preserve the values of an Array for a point in time so I could revert the Array back to those values if needed.
So I declared an empty Temp Array [ ] using the Variable Event Command.
Then, at the appropriate point in the Event, I used the Variable Event Command to say that the Temp Array = the Main Array.
I was expecting that when I removed values from the Main Array after that, the values of the Temp Array would remain as they were. I am using Scripts to remove the values from the Main Array if that matters.
But after things weren't working right and I started checking the values in the Arrays step by step, I noticed that removing a value from the Main Array with a script was also removing that same value from the Temp Array.
Set Main Array [1, 2, 3, 4]
Set Temp Array [ ]
Set Temp Array = Main Array
Result Temp Array [1, 2, 3, 4]
Remove 2 & 3 from the Main Array
Result Main Array [1, 4]
Result Temp Array [1, 4]
Is this normal, expected behavior? Once you say that one Array equals another, when you make a change to one, that apparently changes the other too?
If so, is there another way that I can store the values of an Array at different points in time so I can revert to an earlier set of values when necessary?
I am using arrays to store values and removing some of those values at different times. But there are also times where I need to revert back to what the values in the array were before a set of changes.
For example:
Main Array starts with values 1-10.
4, 5, & 6 are removed (need to save the Main Array values that are left at that point)
3 & 2 are removed but now I need to go back to the values of the Main Array just before that
The only other way I can think of doing this is to store each removed value in a separate Variable and then push all those Variables back into the Array when needed.
Any thoughts?
Thanks!
I wanted to preserve the values of an Array for a point in time so I could revert the Array back to those values if needed.
So I declared an empty Temp Array [ ] using the Variable Event Command.
Then, at the appropriate point in the Event, I used the Variable Event Command to say that the Temp Array = the Main Array.
I was expecting that when I removed values from the Main Array after that, the values of the Temp Array would remain as they were. I am using Scripts to remove the values from the Main Array if that matters.
But after things weren't working right and I started checking the values in the Arrays step by step, I noticed that removing a value from the Main Array with a script was also removing that same value from the Temp Array.
Set Main Array [1, 2, 3, 4]
Set Temp Array [ ]
Set Temp Array = Main Array
Result Temp Array [1, 2, 3, 4]
Remove 2 & 3 from the Main Array
Result Main Array [1, 4]
Result Temp Array [1, 4]
Is this normal, expected behavior? Once you say that one Array equals another, when you make a change to one, that apparently changes the other too?
If so, is there another way that I can store the values of an Array at different points in time so I can revert to an earlier set of values when necessary?
I am using arrays to store values and removing some of those values at different times. But there are also times where I need to revert back to what the values in the array were before a set of changes.
For example:
Main Array starts with values 1-10.
4, 5, & 6 are removed (need to save the Main Array values that are left at that point)
3 & 2 are removed but now I need to go back to the values of the Main Array just before that
The only other way I can think of doing this is to store each removed value in a separate Variable and then push all those Variables back into the Array when needed.
Any thoughts?
Thanks!

