question

qoie200011 avatar image
0 Likes"
qoie200011 asked Julie Weller commented

Custom Code in Global List

Hi there,

I’ve encounter some problem when setting up the field of global list. I want to choose the expression and record which number of processor group the item is assigned to go to. That is, the item has the information label of group number. For this, I have set the destination label as current.inObjects[1].



The token received the label as:

item: /Processor8/Box

puller: id:31


And I also set a label on processor to denote the number of group as the picture below:

I came up with some idea of the custom code as below:

if (value.destination.group==1)

return 1;

elif (value.destination.group==2)

return 2;

elif (value.destination.group==3)

return 3;

elif (value.destination.group==4)

return 4;

else

return 0;


Since I’m new to Flexscript that I’m not sure if this kind of expression will work. Thanks for your help!

FlexSim 23.0.9
custom codeglobal list
圖片1.jpg (19.4 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.

Joerg Vogel avatar image Joerg Vogel commented ·
Please open the parchment roll icon to see, what declared variable exists in the scope of your expression field. Typically you have to reference as a starting point relatively the value you pushed to your list called “value”.

Further on it is a good practice to study what available syntax your programming language consists of. “elif” is not belonging to the namespace of Flexscript. Please look for writing logic in FlexSim‘s manual.

0 Likes 0 ·
Julie Weller avatar image Julie Weller commented ·

Hi @qoie200011, was Felix Möhlmann's answer helpful? If so, please click the "Accept" button at the bottom of their answer. 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 comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Jason Lightfoot commented

There is no "elif" in FlexScript. If group and return value are equal then you can return the label value directly. The "?" makes it so FlexSim will not throw an error if the label does not exist on the object but instead just return 0.

return value.destination.group?
· 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.

Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·
elif can be replaced with "else if" in FlexScript.
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.