question

Stan Davis avatar image
0 Likes"
Stan Davis asked Kari Payton commented

How to programmatically access resource array index

How do you access a specific resource index when an array has been created on the label that references all the acquired resource.

To illustrate, this only changes the color of the object referenced in index 1 even if multiple resources are acquired....

colorlime(getlabel(token, "myoperator"));

Suppose I need to change the color of only the 2nd resource of 3 total acquired resources. How would that be accomplished?

I studied the switch code in the Move Object activity's 'Object From Label Array', but I don't know how to apply it in this scenario.

Thanks

FlexSim 16.2.0
process flow
· 4
5 |100000

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

Matthew Gillespie avatar image Matthew Gillespie ♦♦ commented ·

Just FYI, this will be much easier in FlexSim 2017 which will be out soon (the beta is available now). We've added dot syntax and a new Array type to FlexScript so accessing the 2nd resource would look like this:

token.myOperator[2]
2 Likes 2 ·
Kari Payton avatar image Kari Payton Matthew Gillespie ♦♦ commented ·

@Matthew Gillespie using dot syntax, how can you access all of the acquired resources (i.e. I want both cranes to travel,load item, travel, and unload)? Or is this not possible? This is what the token label looks like:

1 Like 1 ·
cranearray.png (4.3 KiB)
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Kari Payton commented ·

You still need to access each one individually. I would suggest using a RunSubFlow activity to create a child token for each individual crane. See this post (especially Matt Long's model in the comments) for an example of this. For the quantity of child tokens to make you would use:

token.Crane.length
0 Likes 0 ·
Show more comments

1 Answer

·
Sam Stubbs avatar image
2 Likes"
Sam Stubbs answered Mischa Spelt commented

In order to get a reference to specific ranks within your Array, I would set a label as a reference. IN the picklist options for Assign Label Activity under the value field you can select Array > Value from Label Array. This will let you set the index number you're trying to select of which label (In this case whatever label you set your Resource as.)

Then you can use the new label reference you created to alter the color or whatever logic you need.

I've included a simple example.

color-example.fsm


label-array.png (24.4 KiB)
color-example.fsm (20.0 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.

Stan Davis avatar image Stan Davis commented ·

Sam,

That will work for me! I need to remember that while the acquired activity's label is destroyed once all the resources are released, the array reference label persists although now empty. I appreciate the very quick reply.

Stan

0 Likes 0 ·
Mischa Spelt avatar image Mischa Spelt Stan Davis commented ·

Note that in the same menu as in the screenshot, there is also a "Remove Bad References" option which will cut out all items in the array that are no longer pointing to a valid object.

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.