[2.0.76] Reading a fluid from a fluidbox gets the amount from the entity, writing sets the amount to the fluid segment

Post your bugs and problems so we can fix them.
LeonSkills
Inserter
Inserter
Posts: 29
Joined: Mon Feb 11, 2019 12:37 pm
Contact:

[2.0.76] Reading a fluid from a fluidbox gets the amount from the entity, writing sets the amount to the fluid segment

Post by LeonSkills »

The LuaFluidBox API contains the following example
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] = fluid
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.

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

Return to “Bug Reports”