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.

Question about IMyInventory.CanItemsBeAdded()

Discussion in 'Programming Questions and Suggestions' started by spitlermike, Jan 15, 2015.

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

    Messages:
    1
    Hi, I'm new to in-game programming and wanted to develop a script that sorted components and ores to different containers based on their name. I ran into an issue when I tried creating a more sophisticated check to see if a container has enough room than what I have seen, so I took a look at the CanItemsBeAdded Method, which returns a bool if the specific item you are looking at can fit into the container.

    The plan was, use two for loops, one nested in the other, to go through each item in the source inventory, then go through each destination container in my destination container, calling CanItemsBeAdded until it returned true, and then moving the items. I set up Visual Studio using the guide posted in this forum, and when using that method I get no errors. Yet when I paste it into SE, it errors out. Here is how I called the method:

    Code:
                // iterate over sourceItems, moving each item to destination
                for (int i = 0; i < sourceItems.Count; i++) {
                    // Look in each destination container in turn
                    // moving items only when there is space.
                    for (int j = 0; j < destinaton.Count; j++)
                    {
                        destInvOwner = destinaton[j] as IMyInventoryOwner;
                        destInv = destInvOwner.GetInventory(0);
                        [COLOR= #ff0000]if (destInv.CanItemsBeAdded(sourceItems[0].Amount, sourceItems[0].Content.GetId()))[/COLOR]
                        {
                            sourceInv.TransferItemTo(destInv, 0, stackIfPossible: true);
                            break;
                        }
                    }
                }
    
    Does anyone else have any experience with this method? The in-game error says the problem is specifically with the second argument, which I had trouble with in the IDE. It calls for a Sandbox.Common.ObjectBuilders.Definitions.SerializableDefinitionId but I don't know how to satisfy the compiler. Obviously my last attempt failed.

    P.S. I don't like how I did the loops looking back at it now, I plan to change them after I get the method figured out. If I get it figured out...
     
  2. Toiny Trainee Engineer

    Messages:
    2
    I'm having the same problem, can't seem to figure out what parameter is required.
    Any help would be amazing!
     
  3. Phoera Senior Engineer

    Messages:
    1,713
    nope currently, needed type(Sandbox.Common.ObjectBuilders.Definitions.SerializableDefinitionId) restricted to use.
    i found out how to construct it to satisfy compiler, but this is restricted by SE at check step.
     
Thread Status:
This last post in this thread was made more than 31 days old.