question

mikelmb avatar image
0 Likes"
mikelmb asked Carter Walch commented

Trying to program assignation strategy error

Hello,

I am trying to program a assignation strategy an the following error is appearing:

Unknown type Storage.slot in declaration of variable slot

I am trying to prioritize the first level of the rack and then going for the rest of the levels in ascented way. Can someone please help me with this error?

Thanks,

Here is the code

1685033753408.png

FlexSim 22.1.4
rackassignmentsstrategy
1685033753408.png (59.2 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
0 Likes"
Kavika F answered Carter Walch commented

Hey @mikelmb, I think I see a problem with your code. In your first for-loop on line 10, you have a nested for-loop which defines

Slot.slot slot = level.slots[q];

This declares the variable "slot" within the scope of the inner for-loop. That means that whenever the loop repeats, it redeclares it within that scope. As soon as you leave that inner for-loop, "slot" does not exist anymore. So when you try to use "slot" on line 13, it throws an error saying that it doesn't know what you're talking about.

To fix this issue, you can move the "Storage.Slot slot" declaration out between lines 8 and 9 so it is within the scope of your if-statement.

Storage.Level level = bay.levels[w];
Storage.Slot slot = 0;
for (int q = 1; q <= level.slots.length; q++) {
  slot = level.slots[q];

Something along these lines. The same thing will happen with "mustHaveSpace". Honestly, I don't see the point of the inner for-loop since all it does is set "mustHaveSpace" = 1 repeatedly and reassign the slot, eventually to land on the last slot possible. You would get the same functionality if you just had

Storage.Level level = bay.levels[w];
Storage.Slot slot = level.slots[level.slots.length];
int mustHaveSpace = 1;
if (mustHaveSpace && !slot.hasSpace(item)) {...}

But even then you could remove the "mustHaveSpace" variable, unless you're thinking of changing it later. So your if statement could just be

if (!slot.hasSpace(item)) {...}

Now, if you wanted to test each slot to see if it had space and then put the item in there, then you could move the if-statement into the loop, giving you this

Storage.Slot slot = 0;
for (int q = 1; q <= level.slots.length; q++) {
  slot = level.slots[q];
  if (slot.hasSpace(item)) {
    storageItem.assignedSlot = slot;
  }
}

I'm not sure why you have the not (!) in front of your "hasSpace" check if you are trying to assign the slot to it.

Another issue I saw that you could run into is the first

return 0;

The way that your code is written, when executing this for-loop, it will only pass through the first time and return 0 - it will never loop, and it will never get to the second part of your code. You may want to refactor that. But after evaluating your problem, I don't think you even need this second for-loop. If you're trying to simply put items away level by level, then I would remove the second part of your code and move your return statement right after your slot assignment statement.

Hope this helps!

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

Joerg Vogel avatar image Joerg Vogel commented ·

@mikelmb, you have found a still valid but older Flexscript code snippet to assign a slot. Typically you do this by a query clause in a findSlot method. https://answers.flexsim.com/answers/76833/view.html. I struggled about this code snippet myself.


0 Likes 0 ·
mikelmb avatar image mikelmb Joerg Vogel commented ·
Thanks!
0 Likes 0 ·
Carter Walch avatar image Carter Walch mikelmb commented ·

Hi @mikelmb , was Kavika F'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 ·

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.