When a blueprint book is stored in inventory and the active blueprint is deleted or picked up by the player, LuaItemStack::active_index (and the green highlighting square) is immediately moved to the next populated slot in the item_inventory.
However, when a blueprint book is stored in the blueprint library, this update does not happen. Instead, active_index remains stale until the player picks up the book and manually shift-scrolls. Until then, active_index can return a the index of an empty slot or even outside the current size of the item_inventory. This is in spite of the fact that you can still pick up the blueprint book and place a blueprint, without shift-scrolling to properly select it.
For example, the following sequence of actions can reproduce the stale active_index condition:
- Create a new empty blueprint book. Place it in the My Blueprints library. when picked up, item_inventory size is 0. active_index returns nil.
- Create a new blueprint and place it in slot 3 of the empty book. when picked up, item_inventory size is 3, slots 1 and 2 are empty. active_index returns 1. This can be confirmed by the absence of a green square around the blueprint. Blueprint inventory[1] returns nil but does not cause an error.
- Pick up the blueprint book and shift-scroll. active_index is set to 3 and the green square appears around the blueprint.
- Open the blueprint book and move the blueprint from slot 3 to slot 2. inventory size changes to 2, slot 1 is empty. active_index still returns 3, which will cause an out-of-bounds error. Green box disappears.
- Pick up the blueprint book and see that you can still place the blueprint, even though the green square is not shown.
- Pick up the blueprint book and shift-scroll again. active_index is set to 2 and the green square reappears around the blueprint.