question

Manocher Djassemi avatar image
0 Likes"
Manocher Djassemi asked Manocher Djassemi commented

Conditional port code is not sending coded itemtype

@Ben Wilson

I am using the following codes in Flow tab of a Separator. Port 1,2,and 3 are connected to 3 racks.

While the first IF condition sends item 9 to port 2, the second one does not send the item 8 to port 3. It keep sending it to port 1. I ran the model long enough to make sure the condition >=5 is met. Is there anything wrong with these codes? Thanks

if(content(outobject(current,1)) >= 5&& getitemtype(item)==9) {return 2;if(content(outobject(current,1)) >= 5&& getitemtype(item)==8) {return 3;} else {return 1;}}
FlexSim 17.0.3
conditional port
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

·
Ben Wilson avatar image
0 Likes"
Ben Wilson answered Mischa Spelt commented

Yes, you do have some syntax errors. The following code is fixed:

if (content(outobject(current,1)) >= 5 && getitemtype(item)==9) {
   return 2;
}
if (content(outobject(current,1)) >= 5 && getitemtype(item)==8) {
   return 3;
}
else {
   return 1;
}

I added this code to the separator's flow tab, along with some code I stole from a trigger to set a random itemtype and color. After rack 1 is filled with 5 flowitems, the 8s and 9s are properly divided between rack 3 and 2.

Please find sample model attached.

flowtest.fsm


flowtest.fsm (16.0 KiB)
· 2
5 |100000

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

Manocher Djassemi avatar image Manocher Djassemi commented ·

Thanks. It is working now.

0 Likes 0 ·
Mischa Spelt avatar image Mischa Spelt commented ·

You can avoid calling all the functions twice by rewriting it as

if (content(outobject(current,1)) >= 5) {
  int itemType = getitemtype(item);
  if (itemType==9) { return 2;}
  if (itemType==8) { return 3;}
}

return 1;
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.