question

Rocio A avatar image
0 Likes"
Rocio A asked Logan Gold commented

Token label declaration

Hello,

1725618112125.png


In this custom code, if I do not have the ptointermedio label defined for the token at any point in the Process Flow, why does it not give an error?

At what point is the ptointermedio label defined so that it does not cause errors?

This is the process Flow on which the process is based:

1725618231153.png

Thank you.

FlexSim 24.1.1
labeltokenscustomecodedefinition
1725618112125.png (28.6 KiB)
1725618231153.png (42.0 KiB)
· 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.

Logan Gold avatar image Logan Gold ♦♦ commented ·

Hi @Rocio A, 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 Felix Möhlmann commented

Assigning a value to a label will create the label if it is not yet present. Only trying to read a non-existant label will cause an error.

Writing

token.labelName = 1;

is the same as writing

token.labels.assert("labelName").value = 1;

in that regard.

Note that this is only true for labels, not other subnodes or attributes.

· 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.

Jason Lightfoot avatar image Jason Lightfoot ♦♦ commented ·

Also note that these are not the same as

token.labels.assert("labelname",1);

which only sets the label to 1 if the label did not already exist.

0 Likes 0 ·
Rocio A avatar image Rocio A Jason Lightfoot ♦♦ commented ·

I found this structure in the manual that somewhat contradicts what you told me in your last answer.

If there is any difference with your construction, could you explain it to me, please.

Thank you!!

https://docs.flexsim.com/en/24.1/Reference/CodingInFlexSim/FlexScriptAPIReference/Tree/treenode.html

1725866143818.png

0 Likes 0 ·
1725866143818.png (87.3 KiB)
Felix Möhlmann avatar image Felix Möhlmann Rocio A commented ·
The example in the manual combines both expressions. It creates the label if it does not exist yet ("labels.assert("MyLabel", 1)") and then increments the current value of the label by 10. (".value += 10"). If the label did not exist previously (or already had a value of 11) its value would now be 11. If the label did exist with, for example, a value of 7, it would now have a value of 17.

Only using

current.labels.assert("MyLabel").value += 10

would likely result in the value 10, since the label would not get a fixed initial value and most likely get initialized with a value of 0.

0 Likes 0 ·