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.

Inventory Problem since 1.0 Release

Discussion in 'Programming Questions and Suggestions' started by 33iRobot33, Mar 6, 2019.

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

    Messages:
    16
    Hello guys,

    since the new 1.0 release version of space engineers my scripts that focus mostly in displaying my inventory on LCD screens isn't working anymore. I looked up the changelog and found this: "Refactored inventory API".
    But i can't find any sign of what exactly got changed and so i have no idea how to update my script.
    Here is a part of the script and the error message:

    "var cargo = GridTerminalSystem.GetBlockWithName("Black_Flame_Medium_Cargo_Container") as IMyCargoContainer;

    IMyInventory cargoInventory = cargo.GetInventory(0);

    List<IMyInventoryItem> cargoItems = new List<IMyInventoryItem>();
    // Error accurs in the following line:
    cargoItems.AddRange(cargoInventory.GetItems());"

    Error Message: "Error: There is no argument given that cprresponds to the required formal parameter 'items' of 'IMyInventory.GetItems(List<MyInventoryItem>, Func<MyInventoryItem, bool>)' "

    It would be very nice if someone could help me with this or send me a link with some up-to-date API documentation.
     
  2. mojomann71 Senior Engineer

    Messages:
    1,497
  3. 33iRobot33 Trainee Engineer

    Messages:
    16
    I didnt find anything about the inventory changes there
     
  4. Malware Master Engineer

    Messages:
    9,428
    No but you'll find the current up-to-date API list. As you asked for. It's the best you can find, I'm afraid.
     
  5. 33iRobot33 Trainee Engineer

    Messages:
    16
    Ok I finally had time to work through the stuff and fixed it. Thanks you for the link and obviously thanks to malware aswell. Im gonna post the old vs the new version just for people that maybe get here with the same problem.

    Old:

    var cargo = GridTerminalSystem.GetBlockWithName("Black_Flame_Medium_Cargo_Container") as IMyCargoContainer;
    IMyInventory cargoInventory = cargo.GetInventory(0);
    List<IMyInventoryItem> cargoItems = new List<IMyInventoryItem>();
    cargoItems.AddRange(cargoInventory.GetItems());



    Fixed Version:

    var cargo = GridTerminalSystem.GetBlockWithName("Black_Flame_Medium_Cargo_Container") as IMyCargoContainer;
    IMyInventory cargoInventory = cargo.GetInventory(0);
    //Until here everything is the same, the next two lines are important. And don't miss the list has to be MyInventoryItem instead of IMyInventoryItem; missing "I"
    List<MyInventoryItem> cargoItems = new List<MyInventoryItem>();
    cargoInventory.GetItems(cargoItems);


    Another thing to add is that cargoitems.Content.SubtypeName and cargoitems.Content.TypeId don't work anymore. Use cargoitems.Type.SubtypeId and cargoitems.Type.TypeId instead

    There were also changes to the whole Subtype System. If you want to get the right names for items you can use a function i wrote yesterday:


    String decodeItemName(String TypeId, String SubtypeId) {

    if(SubtypeId.Equals("Missile200mm")) {return "Missile Container";}
    else if(SubtypeId.Equals("NATO_25x184mm")) {return "NATO Ammunition Container";}
    else if(SubtypeId.Equals("NATO_5p56x45mm")) {return "NATO Magazine";}
    else if(SubtypeId.Equals("HydrogenBottle")) {return "Hydrogen Bottle";}
    else if(SubtypeId.Equals("OxygenBottle")) {return "Oxygen Bottle";}
    else if(SubtypeId.Equals("AutomaticRifleItem")) {return "Automatic Rifle";}
    else if(SubtypeId.Equals("PreciseAutomaticRifleItem")) {return "Precise Automatic Rifle";}
    else if(SubtypeId.Equals("RapidFireAutomaticRifleItem")) {return "Rapid-Fire Automatic Rifle";}
    else if(SubtypeId.Equals("UltimateAutomaticRifleItem")) {return "Elite Automatic Rifle";}
    else if(SubtypeId.Equals("WelderItem")) {return "Welder";}
    else if(SubtypeId.Equals("Welder2Item")) {return "Enhanced Welder";}
    else if(SubtypeId.Equals("Welder3Item")) {return "Proficient Welder";}
    else if(SubtypeId.Equals("Welder4Item")) {return "Elite Welder";}
    else if(SubtypeId.Equals("AngleGrinderItem")) {return "Grinder";}
    else if(SubtypeId.Equals("AngleGrinder2Item")) {return "Enhanced Grinder";}
    else if(SubtypeId.Equals("AngleGrinder3Item")) {return "Proficient Grinder";}
    else if(SubtypeId.Equals("AngleGrinder4Item")) {return "Elite Grinder";}
    else if(SubtypeId.Equals("HandDrillItem")) {return "Hand Drill";}
    else if(SubtypeId.Equals("HandDrill2Item")) {return "Enhanced Hand Drill";}
    else if(SubtypeId.Equals("HandDrill3Item")) {return "Proficient Hand Drill";}
    else if(SubtypeId.Equals("HandDrill4Item")) {return "Elite Hand Drill";}
    else if(SubtypeId.Equals("BulletproofGlass")) {return "Bulletproof Glass";}
    else if(SubtypeId.Equals("GravityGenerator")) {return "Gravity Generator Component";}
    else if(SubtypeId.Equals("InteriorPlate")) {return "Interior Plate";}
    else if(SubtypeId.Equals("LargeTube")) {return "Large Steel Tube";}
    else if(SubtypeId.Equals("MetalGrid")) {return "Metal Grid";}
    else if(SubtypeId.Equals("PowerCell")) {return "Power Cell";}
    else if(SubtypeId.Equals("RadioCommunication")) {return "Radio Communication Component";}
    else if(SubtypeId.Equals("SmallTube")) {return "Small Steel Tube";}
    else if(SubtypeId.Equals("SolarCell")) {return "Solar Cell";}
    else if(SubtypeId.Equals("SteelPlate")) {return "Steel Plate";}
    else if(SubtypeId.Equals("Superconductor")) {return "Superconductor Conduits";}
    else if(SubtypeId.Equals("Thrust")) {return "Thruster Component";}
    else if(SubtypeId.Equals("Construction") || SubtypeId.Equals("Detector") || SubtypeId.Equals("Medical")
    || SubtypeId.Equals("Reactor")) {return SubtypeId + " Component";}

    else if(TypeId.EndsWith("Ore")) {
    if(SubtypeId.Equals("Stone") || SubtypeId.Equals("Ice") || SubtypeId.Equals("Organic")) {return SubtypeId;}
    else if(SubtypeId.Equals("Scrap")) {return "Scrap Metal";}
    else {return SubtypeId + " Ore";}
    }

    else if(TypeId.EndsWith("Ingot")) {
    if(SubtypeId.Equals("Scrap")) {return "Old Scrap Metal";}
    else if(SubtypeId.Equals("Stone")) {return "Gravel";}
    else if(SubtypeId.Equals("Magnesium")) {return SubtypeId + " Powder";}
    else if(SubtypeId.Equals("Silicon")) {return SubtypeId + " Wafer";}
    else {return SubtypeId + " Ingot";}
    }

    else {return SubtypeId;}
    }
     
Thread Status:
This last post in this thread was made more than 31 days old.