Installa Steam
Accedi
|
Lingua
简体中文 (cinese semplificato)
繁體中文 (cinese tradizionale)
日本語 (giapponese)
한국어 (coreano)
ไทย (tailandese)
Български (bulgaro)
Čeština (ceco)
Dansk (danese)
Deutsch (tedesco)
English (inglese)
Español - España (spagnolo - Spagna)
Español - Latinoamérica (spagnolo dell'America Latina)
Ελληνικά (greco)
Français (francese)
Indonesiano
Magyar (ungherese)
Nederlands (olandese)
Norsk (norvegese)
Polski (polacco)
Português (portoghese - Portogallo)
Português - Brasil (portoghese brasiliano)
Română (rumeno)
Русский (russo)
Suomi (finlandese)
Svenska (svedese)
Türkçe (turco)
Tiếng Việt (vietnamita)
Українська (ucraino)
Segnala un problema nella traduzione
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.