Code: Select all
stack = player.get_inventory(defines.inventory.inventory_main)[index] if player.clean_cursor() then player.cursor_stack.swap_stack(index) end
- There is no hand in the inventory, thus the space for the newly selected item is not reserved.
- There is no guarantee the selected item will be returned to the same inventory slot after it is 'dropped'. (Mostly pertinent to manually-sorted inventories.)
- It's far too easy for a mod author to accidentally destroy inventory contents (i.e. by forgetting to check if clean_cursor() actually succeeded.)
Note: I had previously requested a LuaPlayer::set_selected_index. There used to be a LuaPlayer::get_selected_index, but that appears to be gone as of 0.17