[0.12.35] incorrect .valid return

Bugs that are actually features.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

[0.12.35] incorrect .valid return

Post 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
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [0.12.35] incorrect .valid return

Post by Choumiko »

i think for itemstacks .valid_for_read is the way to check for validity
Rseding91
Factorio Staff
Factorio Staff
Posts: 15903
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.12.35] incorrect .valid return

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Not a bug”