question

Patrick Zweekhorst avatar image
0 Likes"
Patrick Zweekhorst asked Joerg Vogel answered

Bug in getting value from table in ternary operator

Hi All,

I have found a bug in the ternary operator in combination with the table class. If you have the following code you get an exception when it is executed.

Table table = Table( "GlobalTable1");
double x = table[ 1 ][ 1 ] == 0 ? 1 : ( table[ 1 ][ 1 ] );


Flexscript Error VIEW:/active/MainPanel/BackPanel/SplitterXPane/SplitterYPane/ToolTabPane/TabControl/ScriptConsole/Script>script Line 2  
Invalid cast from int to TableElement
Could not finish parsing because of previous errors.

Could you maybe fix this in the next release?

Thanks,

Patrick

FlexSim 18.0.1
tableternary operator
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

if you explicitly cast the false instruction as a number value, there isn't a bug.

· 3
5 |100000

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

Patrick Zweekhorst avatar image Patrick Zweekhorst commented ·

Hi @Jörg Vogel

Thanks for your reply. Do you mean with tonum( table[ 1 ][ 1 ] )? If that is the case is feels quite strange to do this. If you would sum two values from a table you would also not do tonum around each table value. Can you maybe explain a bit more why you would use tonum in this case?

Thanks,

Patrick

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Patrick Zweekhorst commented ·
double x = table[1][1] == 0 ? 1 : table[ 1 ][ 1 ].as(double);
0 Likes 0 ·
Patrick Zweekhorst avatar image Patrick Zweekhorst Joerg Vogel commented ·

Okay, I did not know you could use the cast to double on a TableElement. The autocomplete also did not suggest this. Is there any rule or something on when to use such as cast and when not?

0 Likes 0 ·

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.