question

ROBIN avatar image
0 Likes"
ROBIN asked ROBIN commented

Triggers and SendToPort using code (flexscript)

I have one processor that processes many types of items. I want for each type that enters the processor goes out with another label value. I know this can be done using On Entry trigger but I couldn't do it with code using flexscript.

I also need to send to port depending on the new label value. using flexscript as well.

Thank you in advance.

FlexSim 23.0.15
flexscriptcodetriggers
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

Sri_vikas K avatar image
0 Likes"
Sri_vikas K answered ROBIN commented

Hey @ROBIN

You can set the label of the item on the process entry trigger using the following code.

  1. {
  2. Object involved = item;
  3. string labelname = "Type";
  4. Variant value = duniform(4,6,getstream(current));
  5. involved.color = Color.fromPalette(value);
  6. involved.labels.assert(labelname).value = value;
  7. }

1742886452477.png

And also by giving the following code at Output region in processor properties. I just converted the port by case to flexScript.

  1. Object item = param(1);
  2. Object current = ownerobject(c);
  3. Variant value = item.Type;
  4. if (value == 4) {
  5.     return 1;
  6. }
  7. if (value == 5) {
  8.     return 2;
  9. }
  10. if (value == 6) {
  11.     return 3;
  12. }
  13. return 1;

Port by Case.fsm


1742886452477.png (23.9 KiB)
port-by-case.fsm (27.2 KiB)
· 12
5 |100000

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