[0.13.15] LuaItemStack.valid always returns true

Bugs that are actually features.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1210
Joined: Wed May 18, 2016 4:55 pm
Contact:

[0.13.15] LuaItemStack.valid always returns true

Post by Mooncat »

Descriptions:
LuaEntity.get_output_inventory()[1].valid is always true, even though there is actually no item in the first slot.

Steps to reproduce:
1) Download the attached mod. It is a simple mod just for reproducing this bug.
item-stack-valid-bug_0.0.1.zip
(1.13 KiB) Downloaded 52 times
2) Start a new game.
3) Put a Wooden Chest on the ground. Notice "Item invalid" message should be shown. No error is shown because I added an if statement to check whether the inventory is empty.
4) Put something in its first slot. Notice "Item valid" and the item name should be shown.
5) Put another thing in its second slot. The same messages should still be shown.
6) Take out the item in the first slot. Error will be shown as below:
Bug.png
Bug.png (39.23 KiB) Viewed 897 times
It complains that I should not access item.name whenever item is invalid. Unfortunately, item.valid failed to show the fact.

Expectation:
I expected either LuaEntity.get_output_inventory()[1] is nil or its.valid is false if there is no item in the entity's first slot.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15911
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.13.15] LuaItemStack.valid always returns true

Post by Rseding91 »

It doesn't always return valid. It returns valid if the entity that owns the item stack is still valid.

See: http://lua-api.factorio.com/latest/LuaI ... d_for_read
If you want to get ahold of me I'm almost always on Discord.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1210
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: [0.13.15] LuaItemStack.valid always returns true

Post by Mooncat »

Oh, sorry, I completely missed that. I am so used to the .valid property and haven't thought of other properties. :mrgreen:
Thanks for the info. It is working now.
Post Reply

Return to “Not a bug”