Cài đặt Steam
Đăng nhập
|
Ngôn ngữ
简体中文 (Hán giản thể)
繁體中文 (Hán phồn thể)
日本語 (Nhật)
한국어 (Hàn Quốc)
ไทย (Thái)
Български (Bungari)
Čeština (CH Séc)
Dansk (Đan Mạch)
Deutsch (Đức)
English (Anh)
Español - España (Tây Ban Nha - TBN)
Español - Latinoamérica (Tây Ban Nha cho Mỹ Latin)
Ελληνικά (Hy Lạp)
Français (Pháp)
Italiano (Ý)
Bahasa Indonesia (tiếng Indonesia)
Magyar (Hungary)
Nederlands (Hà Lan)
Norsk (Na Uy)
Polski (Ba Lan)
Português (Tiếng Bồ Đào Nha - BĐN)
Português - Brasil (Bồ Đào Nha - Brazil)
Română (Rumani)
Русский (Nga)
Suomi (Phần Lan)
Svenska (Thụy Điển)
Türkçe (Thổ Nhĩ Kỳ)
Українська (Ukraine)
Báo cáo lỗi dịch thuật
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.