question

Ranggi M avatar image
0 Likes"
Ranggi M asked Eric M commented

Flexscript Coding IF Not Working

Hi, good day

I am using this code with IF but its not working properly,

I count some cummulative value and if it is still <= 1 then, it should be able to pas through an IF. But, when the value is exactly 1 it is not pass through the IF but to the else instead.

Here I attach an example of the coding I used.

The value of variable "Cek" should be 0 until all the looping. But it changes to 1 instead.

Cek Flexcript Coding.fsm


EDITED :

Sorry guys, I made the file example is wrong, the value of kumulatif should be += 1/36 and not "nilai"

Here I attached the correct file again :
cek-flexcript-coding 2.fsm

FlexSim 19.2.4
flexsim 19.2.4coding
· 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.

Eric M avatar image Eric M commented ·

Hi @Ranggi M, was Allister Wilson's or David Chan's answer helpful? If so, please click the red "Accept" button at the bottom of one of their answers. 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 ·
Allister Wilson avatar image
1 Like"
Allister Wilson answered Ranggi M commented

Your code seems to be working fine.

In every iteration where kumulatif is less than or equal to 1, the if branch executes :

breakpoint-if.png

Once kumulatif goes above 1, the else branch executes :

breakpoint-else.png

The final value of kumulatif is 18.5, which is greater than 1, so cek is 1 :

breakpoint-end.png


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

Ranggi M avatar image Ranggi M commented ·

Hello, so sorry I made a mistake in the example file, please find the correct one in the second file. the value of kumulatif become 1.00000 and it goes to "ELSE" and nott "IF"

0 Likes 0 ·
Allister Wilson avatar image Allister Wilson Ranggi M commented ·

This is a floating-point precision issue (not specific to FlexSim), see this answer for more information and ways to avoid it : Incorrect calculation values - FlexSim Community

0 Likes 0 ·
Ranggi M avatar image Ranggi M Allister Wilson commented ·

I see, but In the output windows, the precision unit of the variable kumulatif is 1.00000000 is not it the same as 1 or the output windows is not showing all the decimal precision in Flexsim ? because I tried to changes the if criteria 1 to 1.00000000 and it is still not working.

But anyways, in the end I am changing the IF criteria to " kumulatif <= 1.000000000001" It solve this one example.

Thank you

0 Likes 0 ·
David Chan avatar image
1 Like"
David Chan answered Ranggi M edited

@Ranggi M You might want to check your calculation. The first value is for kumulatif and second value is cek. after a few loop, kumulatif is more than 1.

0.027778,0
0.083333,0
0.166667,0
0.277778,0
0.416667,0
0.583333,0
0.777778,0
1.000000,0
1.250000,1
1.527778,1
1.833333,1
2.166667,1
2.527778,1
2.916667,1
3.333333,1
3.777778,1
4.250000,1
4.750000,1
5.277778,1
5.833333,1
6.416667,1
7.027778,1
7.666667,1
8.333333,1


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

Ranggi M avatar image Ranggi M commented ·

Hello, so sorry I made a mistake in the example file, please find the correct one in the second file. the value of kumulatif become 1.00000 and it goes to "ELSE" and nott "IF"

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.