Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
when you're dealing with lists, in C#, they start counting from zero . So, if you've got 5 containers, they're numbered from 0 to 4 , not from 1 to 5. The problem is that the <= sign in your for loop's condition includes the number of containers itself, which is one too many.
To fix it, just change <= to <
\/ Added Echo statements to help you out.. \/
List<IMyCargoContainer> tainers = new List<IMyCargoContainer>();
GridTerminalSystem.GetBlocksOfType(tainers);
foreach (var container in tainers)
{
var inventory = container.GetInventory(0);
if (inventory != null)
{
var items = inventory.GetItems();
foreach (var item in items)
{
Echo($"Found {item.Amount} {item.Content.SubtypeName} in {container.CustomName}");
}
}
else
{
Echo($"No inventory found in {container.CustomName}");
}
}
Now, your loop will go from 0 up to one less than the number of "tainers" you have.
List<IMyCargoContainer> tainers = new List<IMyCargoContainer>();
GridTerminalSystem.GetBlocksOfType(containers);
for (int i = 0; i <= tainers.Count; i++)
{
var items = tainers .GetInventory(0).GetItems();
foreach (var item in items)
{
Echo($"Found {item.Amount} {item.Content.SubtypeName}");
}
}
I'm not sure why I'm getting" out of range " error.