[2.1.9] LuaEntity::get_fluid_filter errors when trying to query fluid-wagon
Posted: Thu Jul 02, 2026 12:19 am
Fluid wagons have a fluids_count of 1, and it's usually safe to run get_fluid_* functions on an entity if their fluids_count is positive and the provided index falls within the bounds. (And get_fluid_segment_* functions are safe if you check that has_fluid_segment() is true.)
You can reproduce this error by doing the following:
Error: Entity "fluid-wagon", (fluid-wagon) does not have fluids.
I expect the function to return nil.
Similarly, you also produce the error by calling set_fluid_filter. I would expect this function to silently fail as it does in cases, such as crafting machines, where a filter can't be set.
----------------------
EDIT: I'll also mention that this error does not occur on Flamethrower turrets. These have a fluids_count = 2, the second of which is an internal buffer with no associated FluidBox prototype.
You can reproduce this error by doing the following:
- Place a Fluid wagon in the world
- Hover over the wagon with the mouse and run the following command
- /c game.print(game.player.selected.fluids_count)
- to verify the wagon's fluids_count = 1, and then run
- /c filter = game.player.selected.get_fluid_filter(1)
Error: Entity "fluid-wagon", (fluid-wagon) does not have fluids.
I expect the function to return nil.
Similarly, you also produce the error by calling set_fluid_filter. I would expect this function to silently fail as it does in cases, such as crafting machines, where a filter can't be set.
----------------------
EDIT: I'll also mention that this error does not occur on Flamethrower turrets. These have a fluids_count = 2, the second of which is an internal buffer with no associated FluidBox prototype.