[0.14.22] LUA: ItemPrototype.limitations always empty
[0.14.22] LUA: ItemPrototype.limitations always empty
The property limitations of LuaItemPrototype is always empty (I double checked with the # (length) operator). If I look directly in the files in the base-mod I see that it should be filled for at least the productivity modules (which makes sense).
Dev by day, gamer by night
Re: [0.14.22] LUA: ItemPrototype.limitations always empty
Seems to work fine:MatHack wrote:The property limitations of LuaItemPrototype is always empty (I double checked with the # (length) operator). If I look directly in the files in the base-mod I see that it should be filled for at least the productivity modules (which makes sense).
Code: Select all
/c for k, limitation in pairs (game.item_prototypes["productivity-module"].limitations) do game.print(k) end
Re: [0.14.22] LUA: ItemPrototype.limitations always empty
That works for me as well. Diving deeper into the problem, it seems that the #-operator only works for numeric indices. The array is filled with named indices, which is the reason the command below returns 0. Which also explains why my previous code didn't work, because I used ipairs instead of pairs to loop through this array. Lua is weird sometimes...
So... not a bug Thanks for the help Klonan
Code: Select all
/c game.print(#game.item_prototypes["productivity-module"].limitations)
Dev by day, gamer by night
Re: [0.14.22] LUA: ItemPrototype.limitations always empty
As I've been saying to anyone I meet that uses ipairs: ipairs sucks: don't ever use it. pairs does everything ipairs does except it always works.MatHack wrote:That works for me as well. Diving deeper into the problem, it seems that the #-operator only works for numeric indices. The array is filled with named indices, which is the reason the command below returns 0. Which also explains why my previous code didn't work, because I used ipairs instead of pairs to loop through this array. Lua is weird sometimes...
So... not a bug Thanks for the help KlonanCode: Select all
/c game.print(#game.item_prototypes["productivity-module"].limitations)
If you want to get ahold of me I'm almost always on Discord.
Re: [0.14.22] LUA: ItemPrototype.limitations always empty
If it's so bad, why not remove it from the lua engine?Rseding91 wrote:ipairs sucks: don't ever use it. pairs does everything ipairs does except it always works.