question

Craig DIckson avatar image
0 Likes"
Craig DIckson asked Matt Long commented

Referencing tokens in a label array

How do I reference the tokens in the label array? Specifically, I want to read a label "labelStorageLocation" on each of the tokens I just pulled. But since I pulled more than 1, the label "pulled" on the driver token is an array, and I haven't figured out how to read a label array to point to the pulled tokens. I tried this:

getlabel(getlabel(token, "pulled[2]"), "labelStorageLocation")

and also:

getlabel(gettokenbyid(getlabel(token, "pulled[2]")), "labelStorageLocation")

Got a runtime error both times,.I'm sure it's simple ... what have I missed?

Thanks,

Craig

FlexSim 16.1.0
process flowpull from listtokensarrayarray reference
5 |100000

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

Sam Stubbs avatar image
2 Likes"
Sam Stubbs answered Sam Stubbs edited

The simple answer to your question is to use one of the picklist options in the drop down menu. When you are assigning a label value, there's an option for "Value from Label Array." If you know which token you are referencing you can assign that value here.

As a longer answer, if you want to iterate through a Label Array of tokens, there are two good methods to do this. The first being setting up something like a "for loop." In this method you have a token first assign a label referencing the number of items in the array. You can do this using the dropdown option Array > Array Size. This returns the "Number of Items in Array." Create an Index number label, and using the "Value from Label Array" you can reference the token in the array at the specified Index, then increment the Index label, and set a Decide activity. If the Index is less than the size of the array, loop back through and go through the logic again. This mimics the logic of a "for loop" in code.

The other (and preferred) method is to iterate through a Label Array, is using a Sub Flow. This one is like the "for loop" method, but instead, when you create the Sub Flow that handles the logic, you can actually have it create a token for each item in the array simultaneously. In the "Run Sub Flow" activity you can set the number of tokens created to the Sub Flow equal to the size of the array using the same Array > Array Size as mentioned above. And then you can assign each of the Sub Flow tokens a Label with the "Value from Label Array" option and set the index value as the "creationRank" variable of the token. This will create a token for each item in the Label Array, and give it a label referencing the item in the index matching its creationRank.

I've also included the example model below so you can look at it.

pflooping.fsm


5 |100000

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

Craig DIckson avatar image
0 Likes"
Craig DIckson answered Matt Long commented

OK, I was able to do what I wanted by using the value form label array to set a different label, and then using that one to set the remote label.

But it really really would be nice if you could (easily) directly reference a label array e.g.

getlabelarray(token,"lablelArrayedLabel", dPointer)

(Consider that a feature request!)

Thanks,

Craig

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

Matt Long avatar image Matt Long commented ·

If you don't mind coding you can use the following:

treenodearray labelArray = getlabel(token, "labelArray");
treenode myToken = labelArray[1];

In the future we plan to add support for array syntax.

1 Like 1 ·

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.