[0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1

Bugs that are actually features.
Honktown
Smart Inserter
Smart Inserter
Posts: 1058
Joined: Thu Oct 03, 2019 7:10 am
Contact:

[0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1

Post by Honktown »

Was playing a mod (Mobile Factory) which directly inserts pseudo-items into a "printer" entity from a virtual storage (control table with name and amount of items).

If the storage has a fractional value, when the fraction is inserted (inventory.insert({name = "foo", count = amnt}), the error returned is "Item stack count has to be a positive number". There was an immediate <= 0 check right before the insert, so I was thoroughly confused. It turned out the virtual storage had .5 (well .500000000... 5), and this .5 caused the error. Either insert accepts positive numbers >= 1 (untested), or it doesn't accept decimals at all. If the latter, the error would be more accurate if changed to describe needing a positive integer, but if the former, a positive number >= 1.
I have mods! I guess!
Link
Rseding91
Factorio Staff
Factorio Staff
Posts: 16098
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1

Post by Rseding91 »

Thanks for the report. The error message is correct: It's impossible to have < 1 of an item. The way items work is you have integer amounts of them and then a given item has a durability value on it but you still have 1 complete item just with 50% durability.
If you want to get ahold of me I'm almost always on Discord.
Honktown
Smart Inserter
Smart Inserter
Posts: 1058
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1

Post by Honktown »

Rseding91 wrote: Wed Feb 26, 2020 12:26 pm Thanks for the report. The error message is correct: It's impossible to have < 1 of an item. The way items work is you have integer amounts of them and then a given item has a durability value on it but you still have 1 complete item just with 50% durability.
...the error message states "Item stack count has to be a positive number". 0.5 is a positive number. I understand why items only should be in integer amounts, but a "number"
in the non-crazy-pants-on-head-world
is a real number, we have words for these things. Throwing an error saying .5 is not greater than 0 is just not right. (I thought I saw a mod that took .7 ore to produce 1-plate-producing dust... wish I could find it)

To check a recipe, I threw in a mod that transport-belts should need .5 plates. I get a similarly incorrect message:
Mods to disable:Failed to load mods: Error while loading recipe prototype "transport-belt" (recipe): Difficulty normal: Item ingredient can't have count of 0.
.5 is not 0. That one isn't even an opinion. That math is wrong.
I have mods! I guess!
Link
Bilka
Factorio Staff
Factorio Staff
Posts: 3616
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1

Post by Bilka »

.5 is not 0. That one isn't even an opinion. That math is wrong.
https://wiki.factorio.com/Types/ItemIngredientPrototype: amount is an integer. (int)(0.5) = 0.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Honktown
Smart Inserter
Smart Inserter
Posts: 1058
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1

Post by Honktown »

Bilka wrote: Wed Feb 26, 2020 1:08 pm
.5 is not 0. That one isn't even an opinion. That math is wrong.
https://wiki.factorio.com/Types/ItemIngredientPrototype: amount is an integer. (int)(0.5) = 0
Then use the word integer in the message. What's confusing about this.
I have mods! I guess!
Link
Bilka
Factorio Staff
Factorio Staff
Posts: 3616
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1

Post by Bilka »

Honktown wrote: Wed Feb 26, 2020 1:09 pm Then use the word integer in the message. What's confusing about this.
What would the message be for the ItemIngredientPrototype?
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16098
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1

Post by Rseding91 »

Honktown wrote: Wed Feb 26, 2020 1:09 pm
Bilka wrote: Wed Feb 26, 2020 1:08 pm
.5 is not 0. That one isn't even an opinion. That math is wrong.
https://wiki.factorio.com/Types/ItemIngredientPrototype: amount is an integer. (int)(0.5) = 0
Then use the word integer in the message. What's confusing about this.
No idea, you're the one who's confused about integers not accepting floating point values. So, you'd have to explain why you're confused and (seemingly) nobody else is having enough issue to make a bug report about it?
If you want to get ahold of me I'm almost always on Discord.
Honktown
Smart Inserter
Smart Inserter
Posts: 1058
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1

Post by Honktown »

Bilka wrote: Wed Feb 26, 2020 1:10 pm
Honktown wrote: Wed Feb 26, 2020 1:09 pm Then use the word integer in the message. What's confusing about this.
What would the message be for the ItemIngredientPrototype?
Same thing: Amount/Count "needs to be a positive integer." Tells me exactly what's wrong if I give it .5 and have an error. Saying "ingredient count is 0" might make sense to you when you're staring at the C++ side, but that's now what the user gets to see. Saying "Value is not a positive number" is dumb because .5 is a positive number.
Rseding91 wrote: Wed Feb 26, 2020 2:42 pm
Honktown wrote: Wed Feb 26, 2020 1:09 pm
Bilka wrote: Wed Feb 26, 2020 1:08 pm
.5 is not 0. That one isn't even an opinion. That math is wrong.
https://wiki.factorio.com/Types/ItemIngredientPrototype: amount is an integer. (int)(0.5) = 0
Then use the word integer in the message. What's confusing about this.
No idea, you're the one who's confused about integers not accepting floating point values. So, you'd have to explain why you're confused and (seemingly) nobody else is having enough issue to make a bug report about it?
A number is not always an integer, no matter what you think everyone else should think. 0.5 is a positive number and it is not zero. If needed to be an integer, then instead of flooring the float period, just say it can't be a decimal. I'm using code in a way that wasn't expected, and the error message is inaccurate and leads any reader to the wrong conclusion. The error message writer did not expect code to be used in this way, and thought it made sense at the time, but it is not accurate to how one can use the function.
I have mods! I guess!
Link
Post Reply

Return to “Not a bug”