local pricetagColors = {
[3242] = {255, 0, 255},
[6712] = {255, 255, 0}
}
function getPricetagColor(itemnumber)
local r, g, b = 0, 0, 0
if pricetagColors[itemnumber] then
r, g, b = pricetagColors[itemnumber][1], pricetagColors[itemnumber][2], pricetagColors[itemnumber[3]
end
return {r, g, b}
end
好的,所以我现在正在尝试逐步进入 C++。 现在我正试图弄清楚 C++ 中的(复杂的?)数组是如何创建的。 因为我不知道如何用另一种方式解释它,所以我在 LUA 中做了它,因为这是我最了解的。 函数并不重要,重要的是数组,因为我已经搜索了几个小时,但我不知道如何在 C++ 中完成你在 lua 中看到的数组。
最佳答案
看起来你在问题中的内容相当于 std::map<int, std::array<int, 3>>
.
std::map<int, std::array<int, 3>> pricetagColors;
pricetagColors[3242] = {255, 0, 255};
pricetagColors[6712] = {255, 255, 0};
int itemnumber = 3242, r, g, b;
if (pricetagColors.find(itemnumber) != pricetagColors.end())
{
r = pricetagColors[itemnumber][0];
g = pricetagColors[itemnumber][1];
b = pricetagColors[itemnumber][2]; //Note that the comma operator could be used here,
//but it isn't really an idiomatic C++ use
}
关于c++ - lua数组转换成c++数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36097232/