Page 1 of 1

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

Posted: Sun Aug 23, 2020 3:02 am
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).

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

Posted: Sun Aug 23, 2020 6:03 am
by Rseding91
I'm not really sure what the "fix" would be; I could make it return nil if the inventory size is zero?

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

Posted: Sun Aug 23, 2020 9:11 am
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.

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

Posted: Sun Aug 23, 2020 4:51 pm
by Nexela
I second the nil if zero route!

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

Posted: Tue Nov 10, 2020 6:11 am
by smartguy1196
I thirded the nil if zero route!