Instalează Steam
conectare
|
limbă
简体中文 (chineză simplificată)
繁體中文 (chineză tradițională)
日本語 (japoneză)
한국어 (coreeană)
ไทย (thailandeză)
български (bulgară)
Čeština (cehă)
Dansk (daneză)
Deutsch (germană)
English (engleză)
Español - España (spaniolă - Spania)
Español - Latinoamérica (spaniolă - America Latină)
Ελληνικά (greacă)
Français (franceză)
Italiano (italiană)
Bahasa Indonesia (indoneziană)
Magyar (maghiară)
Nederlands (neerlandeză)
Norsk (norvegiană)
Polski (poloneză)
Português (portugheză - Portugalia)
Português - Brasil (portugheză - Brazilia)
Русский (rusă)
Suomi (finlandeză)
Svenska (suedeză)
Türkçe (turcă)
Tiếng Việt (vietnameză)
Українська (ucraineană)
Raportează o problemă de traducere
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.