question

SerenaCR avatar image
0 Likes"
SerenaCR asked SerenaCR commented

Help with custom code

Hello,

I´m trying to set a token label with a custom code.

The idea is to set the value of the bay so that later I can stock an item in that specific one.

I need to stock the item in the first available bay from the floor storage, starting from the right (the bay order is already as follows: (5,4,3,2,1), changed from the properties window)

1669649343690.png

There is a syntax error, but I can not find it.

I´m new to FlexSim so any suggestions or ideas are welcomed.

1669649918220.png


/**Custom Code*/

Object current = param(1);

treenode activity = param(2);

Token token = param(3);

treenode processFlow = ownerobject(activity);


for (int i; i<= rackgetnrofbays; i++){

if (rackgetbaycontent(token.where,i) < 1){

token.bay= i;

if (token.bay != 0){

break;

}

}


FlexSim 22.2.3
using code
1669649343690.png (10.4 KiB)
1669649918220.png (25.7 KiB)
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

·
Kavika F avatar image
1 Like"
Kavika F answered SerenaCR commented

Hey @SerenaCR, there are a few things that may be causing this error. Firstly, you need to initialize "i" to a value:

for (int i = 1; ...)

Next, you can't use rackgetnrofbays like that - it's a function that takes parameters. So you'd have to write something like this:

for (int i = 1; i <= rackgetnrofbays(token.where); i++) {...}

where token.where would be the label on the token with a pointer to the Rack object. I linked the documentation for the function above.

You could also simplify your code by removing the second "if-statement" and putting the "break" after the token.bay assignment. From what I assume, token.bay will start as 0 and you'll assign it to "i" once you find an empty bay. So, you're only going to break out of the for-loop if you've reassigned token.bay. It could look like this:

for (int i = 1; i <= rackgetnrofbays(token.where); i++)
  if (rackgetbaycontent(token.where,i) < 1) {
    token.bay = i;
    break;
  }
}
· 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.

SerenaCR avatar image SerenaCR commented ·
Thank you!!
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.