[0.14.22] LUA: ItemPrototype.limitations always empty

Bugs that are actually features.
Post Reply
User avatar
MatHack
Inserter
Inserter
Posts: 21
Joined: Sat Sep 24, 2016 11:26 am
Contact:

[0.14.22] LUA: ItemPrototype.limitations always empty

Post 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).
Dev by day, gamer by night

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5156
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

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

Post 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

User avatar
MatHack
Inserter
Inserter
Posts: 21
Joined: Sat Sep 24, 2016 11:26 am
Contact:

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

Post 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
Dev by day, gamer by night

Rseding91
Factorio Staff
Factorio Staff
Posts: 13372
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3707
Joined: Tue May 13, 2014 11:06 am
Contact:

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

Post 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?

Post Reply

Return to “Not a bug”