Empty quickbar slot evaluates to valid invalid LuaItemStack

Bugs that are actually features.
sparr
Smart Inserter
Smart Inserter
Posts: 1520
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Empty quickbar slot evaluates to valid invalid LuaItemStack

Post by sparr »

My quickbar is empty.

game.player.get_inventory(defines.inventory.player_quickbar)[1].valid is true
game.player.get_inventory(defines.inventory.player_quickbar)[1].name produces "Error: LuaItemStack API call when LuaItemStack was invalid"...
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5406
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Empty quickbar slot evaluates to valid invalid LuaItemStack

Post by Klonan »

sparr wrote:My quickbar is empty.

game.player.get_inventory(defines.inventory.player_quickbar)[1].valid is true
game.player.get_inventory(defines.inventory.player_quickbar)[1].name produces "Error: LuaItemStack API call when LuaItemStack was invalid"...
The ItemStack was valid, as the object exists,
But it was not valud for read, which is what you should check before trying to read from it:

http://lua-api.factorio.com/latest/LuaI ... d_for_read
Is this valid for reading? Differs from the usual valid in that valid will be true even if the item stack is blank but the entity that holds it is still valid.
sparr
Smart Inserter
Smart Inserter
Posts: 1520
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Empty quickbar slot evaluates to valid invalid LuaItemStack

Post by sparr »

Thanks!

To be clear, is checking valid_for_read the only way to find out if a specific inventory slot is empty?
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Empty quickbar slot evaluates to valid invalid LuaItemStack

Post by Nexela »

That is correct

slot is valid if it is a slot, slot is valid_for_read if it has something in it.
sparr
Smart Inserter
Smart Inserter
Posts: 1520
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Empty quickbar slot evaluates to valid invalid LuaItemStack

Post by sparr »

maybe in the error message replace "invalid" with "not valid_for_read"?
Post Reply

Return to “Not a bug”