Flexscript Coding IF Not Working

Flexscript Coding IF Not Working

ranggi_m
Not applicable
2,261 Views
7 Replies
Message 1 of 8

Flexscript Coding IF Not Working

ranggi_m
Not applicable

[ FlexSim 19.2.4 ]

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

0 Likes
Accepted solutions (1)
2,262 Views
7 Replies
Replies (7)
Message 2 of 8

chanykE2WUT
Collaborator
Collaborator

@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


Message 3 of 8

allister_wilson
Not applicable
Accepted solution

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

Message 4 of 8

ranggi_m
Not applicable

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
Message 5 of 8

ranggi_m
Not applicable

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
Message 6 of 8

allister_wilson
Not applicable

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
Message 7 of 8

ranggi_m
Not applicable

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
Message 8 of 8

eric_m3
Not applicable

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