question

Lucas Antonio Risso avatar image
0 Likes"
Lucas Antonio Risso asked Lucas Antonio Risso commented

What is the best way to set a label to another token?

Sample model.fsmI have tried setting a label using approaches such as token.puller / token.pulled (using lists), token in activity, and arrays.

I am trying to find a more flexible way to set a label on a token without having its precise "location" in the process flow. For doing so, I guess using the "id" is a good idea.

However, using the command token.byID(xx), I could not manage how to edit the information into parenthesis to read a table cel or a token label. This approach is used in the bottom part of the process flow of the attached model.


I would also like to know how to create a reference to a token similarly to the one that have made to the processors, using a global table, and also which is the easiest way to use the token Id as a reference.


Thanks for any help.



FlexSim 22.2.2
labeltoken
sample-model.fsm (33.3 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.

Andrew O avatar image Andrew O ♦ commented ·

Hi @Lucas Antonio Risso, was Kavika F's and Felix Mohlmann'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 unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
Kavika F avatar image
0 Likes"
Kavika F answered Lucas Antonio Risso commented

Hey @Lucas Antonio Risso, the only things guaranteed to be unique about a token are its ID and pointer value, so referencing tokens by ID or pointer address would be your best solution. If you have a random name generation method for your tokens, you could use that too, or just any label that you define that you know is going to be unique. What are you trying to use this reference for? If you provide more details, maybe we could help you with a more specific solution to your problem.

· 6
5 |100000

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

Lucas Antonio Risso avatar image Lucas Antonio Risso commented ·

Hi Kavika,

Thanks for your answer. My doubt is about how to establish the reference/link to another token by using its id. Could you please provide some small example?

I intend to transfer random information between differents parts of my models.

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Lucas Antonio Risso commented ·

It is difficult to give a general answer to this, since there are many possibilities of how to reference other objects in FlexSim and which one is the "best" will depend on the model and logic in question.

To refer to another token you will always need some information that you can use to find the correct token.

The id will probably only be useful if you have a number of persistent tokens that need to be referenced from a different part of the process flow. For example, at the start of your model you create one token for each task executer in a group, so you know those tokens are going to be numbered from 1-N. You can then use the byID method to refer to them.

If you don't know the id beforehand, then you need to store it somewhere where other tokens can access that information. And in that case you can also just store a pointer to the token directly and save the extra step of going through the id.

For example in your model, you could write a reference to the token to the table, instead of just the id. So if you know the correct row number, you can get the token reference directly.

1669108867458.png

1669108837443.png You can also use lists to refer to tokens somewhere else in the process flow, since the token doesn't have to stay at the Push to List activity in order to stay on the list.

1669109212560.png

This can for example be used to reference tokens based on a label value, that is present on the list as a label field. See the attached model for a demonstration.

Finally, if for example the function of the second token is to change a label on the first when a specific event happens, you could create it as a "child" token. Parent and child tokens can refer to each other through the respective methods "token.parent" and "token.children". "token.children" returns an array of all child tokens. To access a particular one, you then have to know its rank (based on the order in which the children were created); "token.children[n]".

sample-model(1).fsm

0 Likes 0 ·
1669108837443.png (7.4 KiB)
1669108867458.png (7.8 KiB)
1669109212560.png (7.0 KiB)
sample-model1.fsm (37.5 KiB)
Lucas Antonio Risso avatar image Lucas Antonio Risso Lucas Antonio Risso commented ·

Hi Felix,

Thank you so much for your answer.

I have tried the approach using a GlobalTable. I guess I committed a mistake of deleting the rows, and then losing the pointer reference. You have clarified it for me.

Also thanks for sharing the idea using the list. This is very interesting.

If possible, one last question, about the token.byID option. As reproduced below, am I trying to use it wrongly?

"However, using the command token.byID(xx), I could not manage how to edit the information into parenthesis to read a table cel or a token label. This approach is used in the bottom part of the process flow of the attached model."

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Lucas Antonio Risso commented ·

I believe the issue you are having comes from the "Token.byID()" requiring/expecting an integer as input, but things like a token label or the return value from reading a table cell are being handled as general "num" type variables.

You can either work around this by first assigning the respective value to an integer variable and then using that in the command.

1669187681592.png

Or by using the old command "gettokenbyid()" instead.

1669187726287.png

sample-model1_1.fsm

0 Likes 0 ·
1669187681592.png (22.7 KiB)
1669187726287.png (5.5 KiB)
sample-model1-1.fsm (38.2 KiB)
Show more comments
Show more comments

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.