question

Enrique Elizaga avatar image
0 Likes"
Enrique Elizaga asked Enrique Elizaga commented

Why do all my array values change?

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?

FlexSim 18.2.3
global tablearray
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Enrique Elizaga commented

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”.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Enrique Elizaga avatar image Enrique Elizaga commented ·

@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.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.