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

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Zeitiah
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Sep 11, 2022 7:59 pm
Contact:

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

Post 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?

SoShootMe
Filter Inserter
Filter Inserter
Posts: 472
Joined: Mon Aug 03, 2020 4:16 pm
Contact:

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

Post 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.

Zeitiah
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Sep 11, 2022 7:59 pm
Contact:

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

Post by Zeitiah »

Awesome, thank you

robot256
Filter Inserter
Filter Inserter
Posts: 594
Joined: Sun Mar 17, 2019 1:52 am
Contact:

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

Post 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.

ColonelSandersLite
Fast Inserter
Fast Inserter
Posts: 208
Joined: Tue Apr 24, 2018 5:42 am
Contact:

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

Post 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.

mrvn
Smart Inserter
Smart Inserter
Posts: 5682
Joined: Mon Sep 05, 2016 9:10 am
Contact:

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

Post by mrvn »

Also beware the the number is rounded to the nearest integer. So 0.5 fluids will read as 0.

SoShootMe
Filter Inserter
Filter Inserter
Posts: 472
Joined: Mon Aug 03, 2020 4:16 pm
Contact:

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

Post 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 :).

ColonelSandersLite
Fast Inserter
Fast Inserter
Posts: 208
Joined: Tue Apr 24, 2018 5:42 am
Contact:

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

Post 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!

mrvn
Smart Inserter
Smart Inserter
Posts: 5682
Joined: Mon Sep 05, 2016 9:10 am
Contact:

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

Post 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.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2484
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

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

Post 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. ;) :)
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

ColonelSandersLite
Fast Inserter
Fast Inserter
Posts: 208
Joined: Tue Apr 24, 2018 5:42 am
Contact:

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

Post 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.

mmmPI
Smart Inserter
Smart Inserter
Posts: 2675
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

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

Post 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

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2484
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

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

Post 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".
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

SoShootMe
Filter Inserter
Filter Inserter
Posts: 472
Joined: Mon Aug 03, 2020 4:16 pm
Contact:

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

Post 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.

mmmPI
Smart Inserter
Smart Inserter
Posts: 2675
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

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

Post 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 )

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

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

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2484
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

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

Post 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.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

mmmPI
Smart Inserter
Smart Inserter
Posts: 2675
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

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

Post 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 ?

mrvn
Smart Inserter
Smart Inserter
Posts: 5682
Joined: Mon Sep 05, 2016 9:10 am
Contact:

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

Post 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.

mrvn
Smart Inserter
Smart Inserter
Posts: 5682
Joined: Mon Sep 05, 2016 9:10 am
Contact:

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

Post 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).

Post Reply

Return to β€œGameplay Help”