question

Thomas JR avatar image
0 Likes"
Thomas JR asked Ben Wilson commented

Error after updating FlexSim

I've just updated from 20.1.3 to the newest version.

At some point in my model I need to access a 2D array.

I simply use bracket syntax, MyArray[row][col] but FlexSim throws this error:

FlexScript exception: Invalid variant type used with [] array operator

It used to work just fine.

Specifically I use two labels of a 3D object as the indices of the 2D-array. Something like this:

int duration = Durations[room.Day][room.Booking_number];

where the labels "Day" and "Booking_number" were created as:

room.Day = 1;
room.Booking_number = 1;

I tried to convert the labels to variant:

Variant row = room.Day;
Variant col = room.Booking_number;
int duration = Durations[room.Day][room.Booking_number];

but without any success.

FlexSim 20.2.3
flexsim 20.2.3array
· 5
5 |100000

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

Joerg Vogel avatar image Joerg Vogel commented ·

And you are absolutely sure, that duration is 2-dimensional array like

[[1,2,3],[4,5,6],[0,1,0]]

, because read_values_of_2dim_array.fsmworks in FlexSim 20.2.3

0 Likes 0 ·
Thomas JR avatar image Thomas JR Joerg Vogel commented ·

@Jörg Vogel

Actually, Duration is also a label of some object, being initialized as

int n = 10;
someObject.Duration = Array(n);

Afterwards I push entries to each main entry like this

someObject.Duration[1].push(35.32);
someObject.Duration[1].push(17.12);
someObject.Duration[1].push(97.38);
someObject.Duration[2].push(3.12);
someObject.Duration[2].push(321.38);
someObject.Duration[3].push(48.32);
...

There are also some entries in the main list to which I don't push any values, e.g. someObject.Duration[5] is empty.

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel commented ·

Perhaps you must declare the value of label room.Day to be of the datatype number as int or double.

0 Likes 0 ·
Thomas JR avatar image Thomas JR Joerg Vogel commented ·

@Jörg Vogel,

Think I found out why. Somehow my model tried to access someObject.Duration where the length of the list is 0.

Still, I wonder why FlexSim didn't complain about an arrayoutofboundexception while instead complaining about an invalid Variant type being used.

1 Like 1 ·
Ben Wilson avatar image Ben Wilson ♦♦ commented ·

Hi @Thomas JR, was Jörg Vogel's answer helpful? If so, please click the red "Accept" button on their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered

I have gone through this again. I don't get any errors.

I have build a model in 20.1.2 and let it run in 20.2.3. I don't still see any errors.multidim_array_20_1.fsm


5 |100000

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