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
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>> 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 }