Why do all my array values change?

Why do all my array values change?

enrique.elizaga
Advocate Advocate
122 Views
2 Replies
Message 1 of 3

Why do all my array values change?

enrique.elizaga
Advocate
Advocate

[ FlexSim 18.2.3 ]

Hi,

I have a Global table with one column that holds array type values.

When I change the value of either one of the array elements, all the arrays in the table change to the same value...even if I change it manually, I can se it before my eyes. Do you know why?

0 Likes
Accepted solutions (1)
123 Views
2 Replies
Replies (2)
Message 2 of 3

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

Straight from the manual:

By default, Arrays are passed around as shared references. This means if you set one Array variable to another Array variable, you are setting the variable to a reference to the first Array, not a copy of the first Array. Thus, if you change either variable's referenced Array data, and it will change it for both variables.

FlexScript class reference : array

Description of online manual version 19 applies for your version,too.

If you need independent copies you use the method “clone”.

0 Likes
Message 3 of 3

enrique.elizaga
Advocate
Advocate

@Jörg Vogel You are right. I made the mistake of copy-pasting cells in the table to "copy format", when really I was copying the array itself. Instead now I am formatting the cell and assigningi it an TABLE[row][col] = ARRAY.clone(). This way it preserves the integrity of each array.