I'm playing Space Engineers, which is a game that allows in-game scripting. I'd like to write a script that refills a ship with certain item types.
The original code just has list of item names:
public readonly List<RequiredItem> requiredItemNames = new List<String>{
"ilder_Component/Construction",
"nt/Computer",
"_Component/Girder",
"ponent/MetalGrid",
"Motor",
"MyObjectBuilder_Component/SteelPlate",
};
But I'd like to retrieve different amounts for different items. I prepared following struct-ish class:
public class RequiredItem {
public RequiredItem(string pattern, double req) {
this.pattern = pattern;
this.amountRequired = req;
}
string pattern;
double amountRequired = 0;
}
I would like to initialize the list without the repetitive new RequiredItem("name", 12345). I somewhat know this syntax from C++, but not from C#. I tried the following:
public readonly List<RequiredItem> requiredItemNames = new List<String>{
{"ilder_Component/Construction", 300}, // construction comp
{"nt/Computer",150},
{"_Component/Girder",100},
{"ponent/MetalGrid",70},
{"Motor",150},
{"MyObjectBuilder_Component/SteelPlate",333}
};
That gives me error:
Error: No oveload for method 'Add' takes 2 arguments
So I suppose it's trying to put the pairs into List.Add instead of my constructor. How can I establish, that I want the items constructed and then put into Add?