How to iterate through floor storage levels?

How to iterate through floor storage levels?

lukas_ker00
Contributor Contributor
206 Views
2 Replies
Message 1 of 3

How to iterate through floor storage levels?

lukas_ker00
Contributor
Contributor

Hi, 
I want to iterate through the levels of my floor storage. For now, I just want to know if the slot in the level is used (an item is placed here) or not. The FloorStorage has 1 Bay, 10 Levels and 1 Slot per level.

Problem: I tried to write a simple for-loop to address this issue. My current approch looks like this: 

Storage.Object storage = Model.find("FloorStorage"); 
 
for (int levelNum = 1; levelNum <= 10; levelNum++) {
  
    // Access the slot in the first bay (Bay 1) at the current level
    Storage.Slot test = storage.getSlot(1, levelNum, 1);
    
    // Check if the slot is occupied
    if (test.items.length > 0) {
        print("Level", levelNum, "is used. Item:", test.items[1].name);
    } else {
        print("Level", levelNum, "is EMPTY.");
    }
}

 

Everytime I execute this code, I receive the following error message which I can't fix right now with my beginner's knowledge: 

time: 1.000000 exception: FlexScript exception: Invalid access to a Storage.Slot label that does not exist at MODEL:/FloorStorage>variables/onSlotEntry at line 0


0 Likes
Accepted solutions (1)
207 Views
2 Replies
Replies (2)
Message 2 of 3

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

in Storgae.Slot there doesn't exist a property "items". "slotItems" is suitable property to get access to an array of stored items. 

Please look into manual to identify usable properties or methods. 

Message 3 of 3

lukas_ker00
Contributor
Contributor

Thank you for your help. 

0 Likes