[Factorio 0.11] Introducing LuaFluidBox (liquid interaction)

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

[Factorio 0.11] Introducing LuaFluidBox (liquid interaction)

Post by drs9999 »

Factorio 0.11.x expands the oppertunities how mods can interact with fluid.
I want to give you a short explanation what's new or was changed.

First off the getliquid() method is gone.
You now gain read/write access via the someEntity.fluidbox, where fluidbox is a table

Each table-entry represents always 1 type of liquid. So the size of the table is bound to the current number of different fluids the entity can hold.

E.g. pipes, steam-engines, tanks always have just one entry, because they can only contain one type of fluid at a time.
Whereas the number of fluidboxes of assembling-machines, refineries etc. can vary depending on the selected recipe.

You can use

Code: Select all

#SomeEntity.fluidbox
to receive the number of fluidboxes for this entity.

For read-access you can simply use

Code: Select all

firstLiquid = SomeEntity.fluidbox[1]
fluidbox[1] returns a table with the following structure:

Code: Select all

{
  name = the fluid's name,
  amount = the current amount,
  temperature = well the current temperature;)
}
Write-access works analog:

Code: Select all

SomeEntity.fluidbox[1] = aFluid
where aFluid has to follow the table-structure described above.
But with the difference that the temperature is optional. If not defined the temperature is set to the default (specified in the prtotype). If the temperature is higher than the max temperature (again defined in the prototype) it is clamped to the max temperature.

Actually I believe that's all you have to know. Let me know if anything is unclear.

User avatar
SHiRKiT
Filter Inserter
Filter Inserter
Posts: 706
Joined: Mon Jul 14, 2014 11:52 pm
Contact:

Re: [Factorio 0.11] Introducing LuaFluidBox (liquid interact

Post by SHiRKiT »

Do you know if only assembling machines and pumps still have access to those fluids boxes? I think I can finally make the liquid splitter with this update, will be trying this week.

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: [Factorio 0.11] Introducing LuaFluidBox (liquid interact

Post by drs9999 »

You can use this with all entities that contain at least one fluidbox.

I haven't tested it, but if you can create a new pipe-entity with more than one box it should be relatively simple.

JamesOFarrell
Filter Inserter
Filter Inserter
Posts: 402
Joined: Fri May 23, 2014 8:54 am
Contact:

Re: [Factorio 0.11] Introducing LuaFluidBox (liquid interact

Post by JamesOFarrell »

This is fantastic, thank you. Saved me a bunch of time. I think fluid.name should be fluid.type though.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: [Factorio 0.11] Introducing LuaFluidBox (liquid interact

Post by bobingabout »

JamesOFarrell wrote:I think fluid.name should be fluid.type though.
Not really.
To define a fluid you use:

Code: Select all

{
type="fluid",
name="water",
....
}
You want to find out what liquid is in the fluid box, and it will return "water" if that's what is in it, therefore you're looking for the fluid's name, so calling it "name" makes most sense.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Modding discussion”