Page 1 of 1

[0.14.22] LUA: ItemPrototype.limitations always empty

Posted: Sun Feb 19, 2017 11:21 am
by MatHack
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).

Re: [0.14.22] LUA: ItemPrototype.limitations always empty

Posted: Sun Feb 19, 2017 11:29 am
by Klonan
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).
Seems to work fine:

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

Posted: Sun Feb 19, 2017 12:23 pm
by MatHack
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...

Code: Select all

/c game.print(#game.item_prototypes["productivity-module"].limitations)
So... not a bug :oops: Thanks for the help Klonan

Re: [0.14.22] LUA: ItemPrototype.limitations always empty

Posted: Sun Feb 19, 2017 5:47 pm
by Rseding91
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...

Code: Select all

/c game.print(#game.item_prototypes["productivity-module"].limitations)
So... not a bug :oops: Thanks for the help Klonan
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.

Re: [0.14.22] LUA: ItemPrototype.limitations always empty

Posted: Mon Feb 20, 2017 4:07 am
by DaveMcW
Rseding91 wrote:ipairs sucks: don't ever use it. pairs does everything ipairs does except it always works.
If it's so bad, why not remove it from the lua engine?