安装 Steam
登录
|
语言
繁體中文(繁体中文)
日本語(日语)
한국어(韩语)
ไทย(泰语)
български(保加利亚语)
Čeština(捷克语)
Dansk(丹麦语)
Deutsch(德语)
English(英语)
Español-España(西班牙语 - 西班牙)
Español - Latinoamérica(西班牙语 - 拉丁美洲)
Ελληνικά(希腊语)
Français(法语)
Italiano(意大利语)
Bahasa Indonesia(印度尼西亚语)
Magyar(匈牙利语)
Nederlands(荷兰语)
Norsk(挪威语)
Polski(波兰语)
Português(葡萄牙语 - 葡萄牙)
Português-Brasil(葡萄牙语 - 巴西)
Română(罗马尼亚语)
Русский(俄语)
Suomi(芬兰语)
Svenska(瑞典语)
Türkçe(土耳其语)
Tiếng Việ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.