If I use this code it doesn't return 1.
if (Table("GlobalTable1")[1][1]) return 1;
I have to do like this ...
if (Table("GlobalTable1")[1][1] > 0) return 1;
Why?
If I use this code it doesn't return 1.
if (Table("GlobalTable1")[1][1]) return 1;
I have to do like this ...
if (Table("GlobalTable1")[1][1] > 0) return 1;
Why?
The bracket operator for the table returns a TableElement type, which you can save off as a Variant. It apparently doesn't cast well to a bool for use in an if statement. I will add an issue to the dev list to improve it. The code you supply above works, as do these alternatives:
Variant value = Table("GlobalTable1")[1][1]; if (value) { return 1; }
if (Table("GlobalTable1")[1][1].as(double)) { return 1; }
I have a big module where I fear I've used this notation everywhere. Do you think it will be ready soon in the new version or it's better to control all the code I have and place ">0" where needed?
You probably should update your code to not use that notation, even if we fix this notation to correctly interpret the boolean comparison of a TableElement as a double Variant.
Floating-point precision is inherently error prone, and if you are doing a comparison with 0, you may get a logical error when the value is 0.000000001 and you get into the if() statement when you don't want to.
I suggest that you update your code to appropriately compare a double value rather than trying to use a double value directly in an if() statement.
Also, even if you wanted to use a double directly in an if() statement, you should use "!=0" instead of ">0" because negative numbers compare to true when performing a boolean comparison. And if you don't want negative numbers to be true, then you absolutely should update your code to ">0" because that's what you meant anyways.
I believe it is because the value in the global table is less than 1. To evaluate to "true", the value must be 1 or greater. If it could be less than 1, then your second way of doing the comparison would be better.
14 People are following this question.
© 1993- FlexSim Software Products, Inc. All Rights Reserved.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.