question

Nouf avatar image
0 Likes"
Nouf asked Nouf action

FlexScript Error in Assign Labels

Hello

In this Project, there is a label shown on the bag, and it is based on two numbers, the first number is the bag cluster a passenger has, the second number is the counter for this cluster. For example, "3|5" means the fifth passenger with three bags (from cluster 3). All bags from this cluster have the same label, meaning there will be three bags for this passenger with the same "3|5" label.

Each bag cluster has a specific destination. I wanted to change the bag's destination based on the counter of the bag's cluster. So I tried this code (image1) in the (assign labels destination activity) , and it worked fine with me.

But when the counter reaches a number above 9, it becomes more than one digits, and of course, it will not work. Therefore, I tried doing this (image2), but I get an error.

Is there any way I can do this in another way?


Note: the same label is shown on the passenger too. Bags arrive randomly too.


SLHS_Level_7.fsm

FlexSim 20.2.2
processflowflexscriptflexsim 20.2.2coding
image1.png (38.5 KiB)
image2.png (44.8 KiB)
slhs-level-7.fsm (6.8 MiB)
5 |100000

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

1 Answer

·
Steven Hamoen avatar image
0 Likes"
Steven Hamoen answered Nouf commented

@Nouf Use the split command. See the user manual here: string.split() and use the "|" as the delimiter.

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

Nouf avatar image Nouf commented ·

I tried the split and substr commands, but I get an error index out of bounds when the counter is less than 10.

0 Likes 0 ·
Steven Hamoen avatar image Steven Hamoen commented ·

@Nouf I think you are thinking to complex. Why isn't this working?

string myString = "13|11";
Array myArray = myString.split("|");
int value1 = myArray[1].toNum();
int value2 = myArray[2].toNum();


0 Likes 0 ·
Nouf avatar image Nouf Steven Hamoen commented ·

You were are right, sorry I was having a hard time and thought about it too much. I tried it again, and it worked.

Thank you so much.

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.