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.

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.

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.

  1. 0.027778,0
  2. 0.083333,0
  3. 0.166667,0
  4. 0.277778,0
  5. 0.416667,0
  6. 0.583333,0
  7. 0.777778,0
  8. 1.000000,0
  9. 1.250000,1
  10. 1.527778,1
  11. 1.833333,1
  12. 2.166667,1
  13. 2.527778,1
  14. 2.916667,1
  15. 3.333333,1
  16. 3.777778,1
  17. 4.250000,1
  18. 4.750000,1
  19. 5.277778,1
  20. 5.833333,1
  21. 6.416667,1
  22. 7.027778,1
  23. 7.666667,1
  24. 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.