Qickbar/LuaInventory: Where do items go that get removed?

Place to get help with not working mods / modding interface.
Post Reply
ibeatbabybiters
Inserter
Inserter
Posts: 30
Joined: Sun Apr 30, 2017 7:14 pm
Contact:

Qickbar/LuaInventory: Where do items go that get removed?

Post 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.
Usually I don't beat babies, but when I do I beat baby biters.

Pandemoneus
Fast Inserter
Fast Inserter
Posts: 127
Joined: Fri May 08, 2015 2:25 pm
Contact:

Re: Qickbar/LuaInventory: Where do items go that get removed?

Post 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
My RSO+Bob's+Angel's modpack: Farlands (outdated)
Mods (current): Resource Labels
Mods (old): Biter Spires

ibeatbabybiters
Inserter
Inserter
Posts: 30
Joined: Sun Apr 30, 2017 7:14 pm
Contact:

Re: Qickbar/LuaInventory: Where do items go that get removed?

Post 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

Code: Select all

InvX.remove(amountOfXInserted)
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?
Usually I don't beat babies, but when I do I beat baby biters.

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

Re: Qickbar/LuaInventory: Where do items go that get removed?

Post 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.

ibeatbabybiters
Inserter
Inserter
Posts: 30
Joined: Sun Apr 30, 2017 7:14 pm
Contact:

Re: Qickbar/LuaInventory: Where do items go that get removed?

Post 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?
Usually I don't beat babies, but when I do I beat baby biters.

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

Re: Qickbar/LuaInventory: Where do items go that get removed?

Post by Nexela »

valid_for_read is the correct way it will only be true if there is an item in the slot

ibeatbabybiters
Inserter
Inserter
Posts: 30
Joined: Sun Apr 30, 2017 7:14 pm
Contact:

Re: Qickbar/LuaInventory: Where do items go that get removed?

Post 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
Usually I don't beat babies, but when I do I beat baby biters.

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: Romner_set