Page 1 of 1

[Factorio 0.11] Introducing LuaFluidBox (liquid interaction)

Posted: Tue Nov 04, 2014 6:21 pm
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.

Re: [Factorio 0.11] Introducing LuaFluidBox (liquid interact

Posted: Mon Nov 10, 2014 8:12 pm
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.

Re: [Factorio 0.11] Introducing LuaFluidBox (liquid interact

Posted: Tue Nov 11, 2014 8:01 am
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.

Re: [Factorio 0.11] Introducing LuaFluidBox (liquid interact

Posted: Tue Nov 11, 2014 8:06 am
by JamesOFarrell
This is fantastic, thank you. Saved me a bunch of time. I think fluid.name should be fluid.type though.

Re: [Factorio 0.11] Introducing LuaFluidBox (liquid interact

Posted: Sat Nov 22, 2014 12:31 am
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.