Factorio.com|Forums|Wiki|Mod Portal|API Docs

# Factorio Runtime Docs Version 2.0.77

# LuaFluidBox - Runtime Docs

## Class LuaFluidBox

An array of fluid boxes of an entity. Entities may contain more than one fluid box, and some can change the number of fluid boxes -- for instance, an assembling machine will change its number of fluid boxes depending on its active recipe. See Fluid.

Do note that reading from a LuaFluidBox creates a new table and writing will copy the given fields from the table into the engine's own fluid box structure. 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. Directly accessing the returned table's attributes won't have the desired effect.

## Example

    -- Double the temperature of the fluid in entity's first fluid box.
    fluid = entity.fluidbox[1]
    fluid.temperature = fluid.temperature * 2
    entity.fluidbox[1] = fluid

## Members

get_prototype(index) | → LuaFluidBoxPrototype or array[LuaFluidBoxPrototype] | The prototype of this fluidbox index. [...]
The prototype of this fluidbox index. [...]
get_capacity(index) | → double | The capacity of the given fluidbox segment.
The capacity of the given fluidbox segment.
get_connections(index) | → array[LuaFluidBox] | The fluidboxes to which the fluidbox at the given index is connected.
The fluidboxes to which the fluidbox at the given index is connected.
get_pipe_connections(index) | → array[PipeConnection] | Get the fluid box's connections and associated data.
Get the fluid box's connections and associated data.
get_filter(index) | → FluidBoxFilter? | Get a fluid box filter
Get a fluid box filter
set_filter(index, filter) | → boolean | Set a fluid box filter. [...]
Set a fluid box filter. [...]
get_locked_fluid(index) | → string? | Returns the fluid the fluidbox is locked onto
Returns the fluid the fluidbox is locked onto
get_fluid_segment_id(index) | → uint32? | Gets the unique ID of the fluid segment this fluid box belongs to. [...]
Gets the unique ID of the fluid segment this fluid box belongs to. [...]
get_fluid_segment_contents(index) | → dictionary[string → uint32]? | Gets counts of all fluids in the fluid segment. [...]
Gets counts of all fluids in the fluid segment. [...]
get_fluid_segment_extent_bounding_box(index) | → BoundingBox? | Gets the current extent bounding box of the fluid segment this fluid box belongs to. [...]
Gets the current extent bounding box of the fluid segment this fluid box belongs to. [...]
flush(index, fluid?) | → dictionary[string → FluidAmount] | Flushes all fluid from this fluidbox and its fluid system.
Flushes all fluid from this fluidbox and its fluid system.
add_linked_connection(this_linked_connection_id, other_entity, other_linked_connection_id) |  | Registers a linked connection between this entity and other entity. [...]
Registers a linked connection between this entity and other entity. [...]
remove_linked_connection(this_linked_connection_id) |  | Removes linked connection record. [...]
Removes linked connection record. [...]
get_linked_connection(this_linked_connection_id) | → LuaEntity?, uint32? | Returns other end of a linked connection.
Returns other end of a linked connection.
get_linked_connections() | → array[FluidBoxConnectionRecord] | Returns list of all linked connections registered for this entity.
Returns list of all linked connections registered for this entity.
owner | :: R LuaEntity | The entity that owns this fluidbox.
The entity that owns this fluidbox.
valid | :: R boolean | Is this object valid? [...]
Is this object valid? [...]
object_name | :: R string | The class name of this object. [...]
The class name of this object. [...]
[] (index) | :: R Fluid? | Access, set or clear a fluid box. [...]
Access, set or clear a fluid box. [...]
# (length) | :: R uint32 | Number of fluid boxes.
Number of fluid boxes.

## Methods

### get_prototype(index) → LuaFluidBoxPrototype or array[LuaFluidBoxPrototype]

The prototype of this fluidbox index. If this is used on a fluidbox of a crafting machine which due to recipe was created by merging multiple prototypes, a table of prototypes that were merged will be returned instead

#### Parameters

index | :: uint32 |

### get_capacity(index) → double

The capacity of the given fluidbox segment.

#### Parameters

index | :: uint32 |

### get_connections(index) → array[LuaFluidBox]

The fluidboxes to which the fluidbox at the given index is connected.

#### Parameters

index | :: uint32 |

### get_pipe_connections(index) → array[PipeConnection]

Get the fluid box's connections and associated data.

#### Parameters

index | :: uint32 |

### get_filter(index) → FluidBoxFilter?

Get a fluid box filter

#### Parameters

index | :: uint32 | The index of the filter to get.
The index of the filter to get.

#### Return values

→ FluidBoxFilter? | The filter at the requested index, or `nil` if there isn't one.

### set_filter(index, filter) → boolean

Set a fluid box filter.

Some entities cannot have their fluidbox filter set, notably fluid wagons and crafting machines.

#### Parameters

index | :: uint32 | The index of the filter to set.
The index of the filter to set.
filter | :: FluidBoxFilterSpec or nil | The filter to set. Setting `nil` clears the filter.
The filter to set. Setting `nil` clears the filter.

#### Return values

→ boolean | Whether the filter was set successfully.

### get_locked_fluid(index) → string?

Returns the fluid the fluidbox is locked onto

#### Parameters

index | :: uint32 |

#### Return values

→ string? | `nil` if the fluidbox is not locked to any fluid.

### get_fluid_segment_id(index) → uint32?

Gets the unique ID of the fluid segment this fluid box belongs to. May return `nil` for fluid wagon, fluid turret's internal buffer or a fluidbox which does not belong to a fluid segment.

#### Parameters

index | :: uint32 |

### get_fluid_segment_contents(index) → dictionary[string → uint32]?

Gets counts of all fluids in the fluid segment. May return `nil` for fluid wagon, fluid turret's internal buffer, or a fluidbox which does not belong to a fluid segment.

Note that this method only ever returns one fluid, since fluids can't be mixed anymore.

#### Parameters

index | :: uint32 |

#### Return values

→ dictionary[string → uint32]? | The counts, indexed by fluid name.

### get_fluid_segment_extent_bounding_box(index) → BoundingBox?

Gets the current extent bounding box of the fluid segment this fluid box belongs to. May return `nil` for fluid wagon, fluid turret's internal buffer, or a fluidbox which does not belong to a fluid segment.

#### Parameters

index | :: uint32 |

### flush(index, fluid?) → dictionary[string → FluidAmount]

Flushes all fluid from this fluidbox and its fluid system.

#### Parameters

index | :: uint32 |
fluid | :: FluidID? | If provided, only this fluid is flushed.
If provided, only this fluid is flushed.

#### Return values

→ dictionary[string → FluidAmount] | The removed fluid.

### add_linked_connection(this_linked_connection_id, other_entity, other_linked_connection_id)

Registers a linked connection between this entity and other entity. Because entity may have multiple fluidboxes, each with multiple connections that could be linked, a unique value for this and other linked_connection_id may need to be given.

It may happen a linked connection is not established immediately due to crafting machines being possible to not have certain fluidboxes exposed at a given point in time, but once they appear (due to recipe changes that would use them) they will be linked. Linked connections are persisted as (this_entity, this_linked_connection_id, other_entity, other_linked_connection_id) so if a pipe connection definition's value of linked_connection_id changes existing connections may not restore correct connections.

Every fluidbox connection that was defined in prototypes as connection_type=="linked" may be linked to at most 1 other fluidbox. When trying to connect already used connection, previous connection will be removed.

Linked connections cannot go to the same entity even if they would be part of other fluidbox.

#### Parameters

this_linked_connection_id | :: uint32 |
other_entity | :: LuaEntity |
other_linked_connection_id | :: uint32 |

### remove_linked_connection(this_linked_connection_id)

Removes linked connection record. If connected, other end will be also removed.

#### Parameters

this_linked_connection_id | :: uint32 |

### get_linked_connection(this_linked_connection_id) → LuaEntity?, uint32?

Returns other end of a linked connection.

#### Parameters

this_linked_connection_id | :: uint32 |

#### Return values

→ LuaEntity? | Other entity to which a linked connection was made
→ uint32? | linked_connection_id on other entity

### get_linked_connections() → array[FluidBoxConnectionRecord]

Returns list of all linked connections registered for this entity.

## Attributes

### owner :: Read LuaEntity

The entity that owns this fluidbox.

### valid :: Read boolean

Is this object valid? This Lua object holds a reference to an object within the game engine. It is possible that the game-engine object is removed whilst a mod still holds the corresponding Lua object. If that happens, the object becomes invalid, i.e. this attribute will be `false`. Mods are advised to check for object validity if any change to the game state might have occurred between the creation of the Lua object and its access.

### object_name :: Read string

The class name of this object. Available even when `valid` is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.

## Operators

### [] (index)

Access, set or clear a fluid box. The index must always be in bounds (see LuaFluidBox::length_operator). New fluidboxes may not be added or removed using this operator.

Is `nil` if the given fluid box does not contain any fluid. Writing `nil` removes all fluid from the fluid box.

### # (length)

Number of fluid boxes.

Class used in

- LuaEntity::fluidbox
- LuaFluidBox::get_connections()
- PipeConnection