Page 1 of 1
[0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1
Posted: Wed Feb 26, 2020 7:57 am
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.
Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1
Posted: Wed Feb 26, 2020 12:26 pm
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.
Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1
Posted: Wed Feb 26, 2020 1:00 pm
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.
Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1
Posted: Wed Feb 26, 2020 1:08 pm
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.
Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1
Posted: Wed Feb 26, 2020 1:09 pm
by Honktown
Then use the word integer in the message. What's confusing about this.
Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1
Posted: Wed Feb 26, 2020 1:10 pm
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?
Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1
Posted: Wed Feb 26, 2020 2:42 pm
by Rseding91
Honktown wrote: Wed Feb 26, 2020 1:09 pm
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?
Re: [0.18.8] inventory.insert() has inaccurate error message for 0 < count < 1
Posted: Wed Feb 26, 2020 3:13 pm
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
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.