Page 1 of 1
Qickbar/LuaInventory: Where do items go that get removed?
Posted: Sun Jun 04, 2017 7:49 pm
by ibeatbabybiters
I have stone walls in my quickbar and when I execute this command:
Code: Select all
/c game.players[1].character.get_inventory(defines.inventory.player_quickbar).remove("stone-wall")
then the stone wall is correctly removed, but where does it go? Because it doesn't appear in the main inventory.
Next, when I do
Code: Select all
/c game.players[1].character.get_inventory(defines.inventory.player_quickbar).insert("stone-wall")
then the stone wall magically appears in the quickbar, even if there is no stone wall in the inventory.
Same behavior with the clear method, by the way.
Re: Qickbar/LuaInventory: Where do items go that get removed?
Posted: Sun Jun 04, 2017 9:22 pm
by Pandemoneus
Maybe it's "remove" as in "delete"?
And for your second point, since you are using "defines.inventory.player_quickbar", why would you expect it not to go to the quickbar?
If you are trying to move items from an inventory to another, you will probably have to do the following procedure:
Assume you want to move the item X from inventory InvX to inventory InvY:
Code: Select all
if InvY.can_insert(X) then
amountOfXInserted = InvY.insert(X)
InvX.remove(amountOfXInserted)
end
Re: Qickbar/LuaInventory: Where do items go that get removed?
Posted: Sun Jun 04, 2017 11:04 pm
by ibeatbabybiters
Pandemoneus wrote:Maybe it's "remove" as in "delete"?
And for your second point, since you are using "defines.inventory.player_quickbar", why would you expect it not to go to the quickbar?
I think you misunderstood, what I don't get is: if it's really "delete" then where does it suddenly come from when I call insert("stone-wall")? I have no stone wall in my main inventory after I call remove, yet it appears back when I do an insert right after. Is there some parallel universe where removed items temporary stay?
If you are trying to move items from an inventory to another, you will probably have to do the following procedure:
Assume you want to move the item X from inventory InvX to inventory InvY:
Code: Select all
if InvY.can_insert(X) then
amountOfXInserted = InvY.insert(X)
InvX.remove(amountOfXInserted)
end
Thanks a lot! Still kind of confused how this is supposed to work but i'll play a bit more with it.
But how is
supposed to work, though, if amountOfXInserted is just a number? Shouldn't it be something like
Code: Select all
InvX.remove({ name = "stone-wall", count = amountOfXInserted })
instead?
Also, I have noticed that moving blueprints or power armor between inventories will make them empty. Any idea why, and how this can be prevented if possible?
Re: Qickbar/LuaInventory: Where do items go that get removed?
Posted: Sun Jun 04, 2017 11:14 pm
by Nexela
insert and remove use SimpleItemStacks which is basically an item and a count (as well as health/durability/ammo)
inv.remove({name = "stone-wall", count = 20}) simply trys to remove 20 stone-walls from the game (it returns the number that were actually removed) ie if you only have 10 in the inventory it would return 10
inv.insert(...) does the same thing just inserts x amount of the generic named item into an inventory.
so inv.remove("power-armor") finds the first stack of power-armor and removes it completly
and inv.insert("power-armor") inserts a generic power-armor
To move the actual luaItemStack and not a simpleitemstack you would use things like set_stack and clear.
Re: Qickbar/LuaInventory: Where do items go that get removed?
Posted: Mon Jun 05, 2017 12:22 am
by ibeatbabybiters
I totally misunderstood how this works, now it's crystal clear, thanks a lot guys!

Also set_stack and clear is exactly what I needed.
One last question: If I want to search for an empty LuaItemStack in an inventory, is it safe to use the "valid_for_read" property for this purpose (e.g. when false then it's empty from my experience), or is there a better way?
Re: Qickbar/LuaInventory: Where do items go that get removed?
Posted: Mon Jun 05, 2017 5:31 am
by Nexela
valid_for_read is the correct way it will only be true if there is an item in the slot
Re: Qickbar/LuaInventory: Where do items go that get removed?
Posted: Mon Jun 05, 2017 6:21 pm
by ibeatbabybiters
Thank you very much! With your help I was able to create my first mod, Quickbar Switcher:
viewtopic.php?f=92&t=49335