[2.0.76] Reading a fluid from a fluidbox gets the amount from the entity, writing sets the amount to the fluid segment
Posted: Sun May 17, 2026 1:43 pm
The LuaFluidBox API contains the following example
If you run this code it sets the fluid amount that was in entity to the whole fluid segment it is connected to.
For example run this code on a fluid segment with just two storage tanks, both full with 25k. So the full fluid segment has 50k.
The result is that both now have 12.5k. The total fuel segment contains the 25k that was initially in the selected storage tank, we've lost 25k.
I expect reading and writing to be consistent. So either the amount when reading is from the whole network, or (preferably) when writing sets it only to the entity the fluidbox belongs to (and then immediately equalises it amongst the rest of the fluid segment).
Therefore, the correct way to update a fluidbox of an entity is to read it first, modify the table, then write the modified table back
Code: Select all
fluid = entity.fluidbox[1]
fluid.temperature = fluid.temperature * 2
entity.fluidbox[1] = fluidFor example run this code on a fluid segment with just two storage tanks, both full with 25k. So the full fluid segment has 50k.
Code: Select all
entity = game.player.selected
fluid = entity.fluidbox[1]
game.print(fluid.amount)
entity.fluidbox[1] = fluid
game.print(entity.fluidbox[1].amount)I expect reading and writing to be consistent. So either the amount when reading is from the whole network, or (preferably) when writing sets it only to the entity the fluidbox belongs to (and then immediately equalises it amongst the rest of the fluid segment).