Page 1 of 1

[0.12.35] incorrect .valid return

Posted: Fri Jun 03, 2016 6:51 pm
by Adil
If armor slot is empty, it is valid for some reason. But you cannot access other fields of it.

Code: Select all

script.on_event(defines.events.on_player_created,function(e)
    local p=game.players[e.player_index]
    local armor=p.get_inventory(defines.inventory.player_armor)[1]
    print (armor.valid)
    if not (armor and armor.valid and armor.has_grid) then 
         -this will give error
    end
end)

Code: Select all

Error while running the event handler: __Advanced_Personal_Defense__/control.lua:42: LuaItemStack API call when LuaItemStack was invalid

Re: [0.12.35] incorrect .valid return

Posted: Fri Jun 03, 2016 7:19 pm
by Choumiko
i think for itemstacks .valid_for_read is the way to check for validity

Re: [0.12.35] incorrect .valid return

Posted: Fri Jun 03, 2016 8:00 pm
by Rseding91
Choumiko wrote:i think for itemstacks .valid_for_read is the way to check for validity
Correct. The note in the docs about valid_for_read explain the difference and why .valid reports true but you get the error.

http://lua-api.factorio.com/0.12.35/Lua ... 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.