When a logistic net has a negative amount of a good, using the API to get the amount the logistic network contains reports a ridiculously high number.
https://imgur.com/a/LBRdG
I'm not sure exactly how to reproduce the negative amount, but it seems like a case of trying to assign an unsigned int from a signed int.
[0.15.40] LuaLogisticNetwork.get_item_count(item) overflow
Re: [0.15.40] LuaLogisticNetwork.get_item_count(item) overflow
Logistic network readout has a few caveats.
1) Items transported by robots are not shown in any readout.
2) Negative amounts happen because bots are scheduled to pick up their cargo capacity regardless of how much is in storage.
Together those can produce negative numbers quite often in networks with low storage amounts.
To me that looks like that window is displaying the values as unsigned 32bit or 64bit int while internally Factorio uses 32bit signed int.
You could possibly do something like this to read the MSB as sign.
1) Items transported by robots are not shown in any readout.
2) Negative amounts happen because bots are scheduled to pick up their cargo capacity regardless of how much is in storage.
Together those can produce negative numbers quite often in networks with low storage amounts.
To me that looks like that window is displaying the values as unsigned 32bit or 64bit int while internally Factorio uses 32bit signed int.
You could possibly do something like this to read the MSB as sign.
My Mods: mods.factorio.com
Re: [0.15.40] LuaLogisticNetwork.get_item_count(item) overflow
Thanks for the report. This was fixed for 0.16 a few months ago.
If you want to get ahold of me I'm almost always on Discord.