[Rseding91] [1.0.0] active_index is 1 for a brand new empty blueprint book, is error to use this as inventory index

This subforum contains all the issues which we already resolved.
Post Reply
sparr
Smart Inserter
Smart Inserter
Posts: 1234
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

[Rseding91] [1.0.0] active_index is 1 for a brand new empty blueprint book, is error to use this as inventory index

Post by sparr »

A brand new blueprint book on the cursor has LuaItemStack.active_index == 1, but LuaItemStack.get_inventory(defines.inventory.item_main)[1] is an error because that inventory has a length of zero. I can, of course, check the length and compare it to the index, but it doesn't seem right that the active index is ever an invalid index that is not also an invalid value for indexing in general (like, say, nil).

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

Re: [1.0.0] active_index is 1 for a brand new empty blueprint book, is error to use this as inventory index

Post by Rseding91 »

I'm not really sure what the "fix" would be; I could make it return nil if the inventory size is zero?
If you want to get ahold of me I'm almost always on Discord.

sparr
Smart Inserter
Smart Inserter
Posts: 1234
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [1.0.0] active_index is 1 for a brand new empty blueprint book, is error to use this as inventory index

Post by sparr »

At least a couple of existing mods assume that active_index will be nil when it's not to be used as an index. I found this while fixing one of them. I would expect it to be nil, as well.

Nexela
Smart Inserter
Smart Inserter
Posts: 1822
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [1.0.0] active_index is 1 for a brand new empty blueprint book, is error to use this as inventory index

Post by Nexela »

I second the nil if zero route!


Post Reply

Return to “Resolved Problems and Bugs”