Page 1 of 2

Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Sun Sep 11, 2022 8:08 pm
by Zeitiah
I want to check to see how much of a fluid is in the wagon, and disable the pump if its below a certain point. Is it possible to check how much fluid is in a fluid wagon in order to disable a pump?

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Sun Sep 11, 2022 8:47 pm
by SoShootMe
Zeitiah wrote:
Sun Sep 11, 2022 8:08 pm
Is it possible to check how much fluid is in a fluid wagon in order to disable a pump?
For a train at a train stop, you can read its contents through a circuit connection to the train stop. That is the sum of all wagons rather than an individual wagon, but it is the closest you can get.

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Sun Sep 11, 2022 9:18 pm
by Zeitiah
Awesome, thank you

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 12:01 pm
by robot256
If you want to know the contents of a specific wagon, and not the whole train (if more than one wagon have the same fluid), you have to use the Inventory Sensor mod. It uses resources checking for something to read all the time but does what it says.

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 3:39 pm
by ColonelSandersLite
SoShootMe wrote:
Sun Sep 11, 2022 8:47 pm
Zeitiah wrote:
Sun Sep 11, 2022 8:08 pm
Is it possible to check how much fluid is in a fluid wagon in order to disable a pump?
For a train at a train stop, you can read its contents through a circuit connection to the train stop. That is the sum of all wagons rather than an individual wagon, but it is the closest you can get.
This is correct but I want to point out a small exception and give you a warning.

The exception would be the situation where your fluid wagons have different fluids in them. In that case it's trivial but I suspect this isn't the situation you're interested in.


So the warning -
Fluid counts have decimal points. Circuit networks only allow integers and they truncate. Depending on what exactly it is that you're trying to do, this can cause some big problems. Just by way of example, suppose that your fluid wagon has 0.8723 oil in it. The circuit network will read that as 0. If you actually need precision, you'll have to deal with barrels.

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 3:57 pm
by mrvn
Also beware the the number is rounded to the nearest integer. So 0.5 fluids will read as 0.

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 4:38 pm
by SoShootMe
ColonelSandersLite wrote:
Mon Sep 12, 2022 3:39 pm
Circuit networks only allow integers and they truncate.
mrvn wrote:
Mon Sep 12, 2022 3:57 pm
Also beware the the number is rounded to the nearest integer.
At most one of these statements can be correct :).

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 4:40 pm
by ColonelSandersLite
SoShootMe wrote:
Mon Sep 12, 2022 4:38 pm
ColonelSandersLite wrote:
Mon Sep 12, 2022 3:39 pm
Circuit networks only allow integers and they truncate.
mrvn wrote:
Mon Sep 12, 2022 3:57 pm
Also beware the the number is rounded to the nearest integer.
At most one of these statements can be correct :).
I'm pretty sure that it's truncation but It's possible that I'm wrong. It has happened!

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 4:43 pm
by mrvn
SoShootMe wrote:
Mon Sep 12, 2022 4:38 pm
ColonelSandersLite wrote:
Mon Sep 12, 2022 3:39 pm
Circuit networks only allow integers and they truncate.
mrvn wrote:
Mon Sep 12, 2022 3:57 pm
Also beware the the number is rounded to the nearest integer.
At most one of these statements can be correct :).
Depends on your definition of nearest. :)

ColonelSanderLite is probably correct though. My points stands though that checking if fluid is 0 doesn't work and leaves tiny bits in the train.

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 4:47 pm
by FuryoftheStars
For clarity sake, you probably should say "rounded down to the nearest integer", because otherwise mine (and I suspect many other's) interpretation of your line would mean that 0.5 rounds to 1, not 0. ;) :)

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 4:52 pm
by ColonelSandersLite
FuryoftheStars wrote:
Mon Sep 12, 2022 4:47 pm
For clarity sake, you probably should say "rounded down to the nearest integer"
That *hurts* my programmer brain because it's self contradicting... I think I know what it means but my brain thinks it's some kinda cruel buddist khone or something.

That being said, I checked the wiki for an answer to this after my last post and it says
When reading the content of a stopped train, fluid amounts are rounded down to the nearest integer, except when the fluid amount is < 1, then it is is rounded to 1.
Same self-contradiction but the second part is new. Wonder when that happened? I'm assuming it's accurate.

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 5:12 pm
by mmmPI
ColonelSandersLite wrote:
Mon Sep 12, 2022 4:52 pm
Same self-contradiction but the second part is new. Wonder when that happened? I'm assuming it's accurate.
https://wiki.factorio.com/index.php?tit ... did=182702

Given that the changed occured between October and December 2020. It would seem that it is the case since the version 1.1

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 5:43 pm
by FuryoftheStars
ColonelSandersLite wrote:
Mon Sep 12, 2022 4:52 pm
FuryoftheStars wrote:
Mon Sep 12, 2022 4:47 pm
For clarity sake, you probably should say "rounded down to the nearest integer"
That *hurts* my programmer brain because it's self contradicting... I think I know what it means but my brain thinks it's some kinda cruel buddist khone or something.
Can you better define what you mean? I don't follow.

Also, my reply was more aimed at mrvn as their post merely said "rounded to the nearest integer".

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 6:00 pm
by SoShootMe
ColonelSandersLite wrote:
Mon Sep 12, 2022 4:52 pm
FuryoftheStars wrote:
Mon Sep 12, 2022 4:47 pm
For clarity sake, you probably should say "rounded down to the nearest integer"
That *hurts* my programmer brain because it's self contradicting...
I get where you're coming from but I think it can be read as precise, not a contradiction: down tells you the rounded value must not be greater than the true value, nearest tells you the rounded value must have the least absolute difference to the true value (arguably implied by "rounded"), and integer tells you the rounding is to that rather than (say) a multiple of ten.
That being said, I checked the wiki for an answer to this after my last post and it says
When reading the content of a stopped train, fluid amounts are rounded down to the nearest integer, except when the fluid amount is < 1, then it is is rounded to 1.
I should have checked the Wiki myself... I had a feeling there was some exceptional behaviour but wasn't certain so cut it before posting.

I'm not sure it's quite right though, I think it should be "when 0 < fluid amount < 1", ie exactly 0 gives no signal. This means a signal will be present unless there is no fluid.

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 6:02 pm
by mmmPI
If you round to the nearest integer, it's sometimes rounded up, sometimes rounded down, if you always round down (to an integer) the name is truncated. ( that was for fury, i guess that explain why it could mess with some people's brain )

But if for only 1 number you are not truncating ? then you got the factorio wiki :D

( agree with shootme)

(had to edit to be precise duh )

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 6:18 pm
by Bilka
Seems like the quoted sentence is of my creation. I don't understand the confusion about rounded down. I'm very used to the word "abrunden", which is my first language version of "rounded down". The fact that I can link to a wikitionary entry of that makes it a "real word" to me, not just an invention of my German brain wanting an English equivalent :P

Anyway, better phrasing ideas that still convey truncated to nearest integer/rounded down to nearest integer and the < 1 but > 0 special case of rounding to 1 are appreciated/invited to be implemented on the wiki.

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 6:28 pm
by FuryoftheStars
SoShootMe wrote:
Mon Sep 12, 2022 6:00 pm
ColonelSandersLite wrote:
Mon Sep 12, 2022 4:52 pm
FuryoftheStars wrote:
Mon Sep 12, 2022 4:47 pm
For clarity sake, you probably should say "rounded down to the nearest integer"
That *hurts* my programmer brain because it's self contradicting...
I get where you're coming from but I think it can be read as precise, not a contradiction: down tells you the rounded value must not be greater than the true value, nearest tells you the rounded value must have the least absolute difference to the true value (arguably implied by "rounded"), and integer tells you the rounding is to that rather than (say) a multiple of ten.
This is exactly how I meant it and as I've always understood that phrase to mean. Without the specification of "nearest integer", you're leaving it open to interpretation that could mean to the nearest multiple of 10, or 1/10th.

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 6:59 pm
by mmmPI
Bilka wrote:
Mon Sep 12, 2022 6:18 pm
I don't understand the confusion about rounded down
Anyway, better phrasing ideas that still convey truncated to nearest integer/rounded down to nearest integer and the < 1 but > 0 special case of rounding to 1 are
I don't think it's confusing when you say rounded down to the nearest integer, i guess it comes from how you learn it. Roundings is the word i remember from physic class where you need to know how many signficant digits should be indicated given the precisions of your measure, it doesn't have to be an integer although it could be, you can have a number like 12.2423 and say it's rounded up or down, to the xth digit to keep the number of significant digits. maybe the number was 12.2423299632... because you got it from a division but your measure instrument is not as precise enough for the last digits to mean anything so you round off the number.

Truncated would be the math teacher word (and computer science) to describe the process of discarding the part that is after the decimal point. And if you were to call it a rounded down number the teacher would tell you that you are not in physics class :)

At least that was the case with french teacher, there are the equivalent of the two words as in english, "arrondi"= rounded ; "troncature" = truncation. The french part of the wiki doesn't contain translation for this particular part to illustrate though.

In english there is also the "floor" function, i'm not sure which one is the most precise for describing what happens in factorio, especially if there is 2 different method for different interval.



Edit: Though , looking at it a bit more, ColonelSanders used the word " selfcontradiction" and not "confusion", i think then it would refers to something like 14.7 being rounded to down to 14, which is then not the "nearest" integer ?

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 7:51 pm
by mrvn
ColonelSandersLite wrote:
Mon Sep 12, 2022 4:52 pm
When reading the content of a stopped train, fluid amounts are rounded down to the nearest integer, except when the fluid amount is < 1, then it is is rounded to 1.
Same self-contradiction but the second part is new. Wonder when that happened? I'm assuming it's accurate.
Wow, that has been a feature request for ages and the devs where on the fence about that change. I hope it's true, this was so annoying when dealing with fluid wagons and circuit porgraming.

Re: Is it possible to read the amount of fluid in a fluid wagon and output the result to a signal?

Posted: Mon Sep 12, 2022 7:53 pm
by mrvn
Bilka wrote:
Mon Sep 12, 2022 6:18 pm
Seems like the quoted sentence is of my creation. I don't understand the confusion about rounded down. I'm very used to the word "abrunden", which is my first language version of "rounded down". The fact that I can link to a wikitionary entry of that makes it a "real word" to me, not just an invention of my German brain wanting an English equivalent :P

Anyway, better phrasing ideas that still convey truncated to nearest integer/rounded down to nearest integer and the < 1 but > 0 special case of rounding to 1 are appreciated/invited to be implemented on the wiki.
For a programmer "round" is the function where "abs(x - round(x))" is smallest and 0.5 rounds to 1. Like people round numbers.

"rounded down" is "floor" or simply truncated and "rounded up" is "ceil"(ing).