Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Findout if items Stack

Discussion in 'Programming Questions and Suggestions' started by Pingger, Sep 22, 2017.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Pingger Trainee Engineer

    Messages:
    53
    Hi,

    I'm currently working on a station management script.
    One of the features of the Script should be, that it sorts all inventories. Since there are quite a few inventories I need to know if items stack when I move them/ if I should move them since they might not stack. And using IMyInventory.GetItems() uses loads of runtime, so I can't call it after each Inventory change (I could, but then the UPS might drop below 10).

    My First attempt was using the HashCodes of the Items, since these were different for each item stack type, so two gravel stacks had the same hash, but two grinders didn't ... Unfortunately I had a mistake in my programming, that tried to stack the grinders, which caused them to all have the same hash code (no idea why tho) and more interesting now the oxygen bottles also have the same hash as the grinders ...
    TL: DR HashCodes can't be used to compare items of same or different types, since at some point these hash codes might become identical.

    There is also no method I could find, that allowed me to check if the Item is stackable. I could find out, by taking the item, putting it in the same container and get me a new List of Items in that container and check if the amount of stacks has changed, but this eats runtime for breakfast...

    Does anyone know a method with a low runtime impact, that allows me check if items can stack?

    Greetings
    Pingger
     
Thread Status:
This last post in this thread was made more than 31 days old.