Page 1 of 1

LuaTrain.get_contents() for fluids

Posted: Sat May 13, 2017 4:30 am
by Optera
Items have nice api functions like train.get_contents() and train.get_item_count(item).

Why do fluids require us to iterate over every fluidbox in every wagon?

Code: Select all

for _, wagon in pairs(train.fluid_wagons) do
  for i=1, #wagon.fluidbox do
You already do that internally to display fluids at stops and in train tooltip.

Re: LuaTrain.get_contents() for fluids

Posted: Sat May 13, 2017 8:54 pm
by Rseding91
get_contents can't return items and fluids because the names can collide and it's a string -> count mapping.

I could add get_fluid_contents (and all the other same methods that items have but for fluids).

Re: LuaTrain.get_contents() for fluids

Posted: Sun May 14, 2017 4:54 am
by Optera
Rseding91 wrote:get_contents can't return items and fluids because the names can collide and it's a string -> count mapping.

I could add get_fluid_contents (and all the other same methods that items have but for fluids).
That would be just as fine.
Since I don't plan on supporting mixed trains (yet) it'd boil down to.

Code: Select all

inventory = train.get_contents() or train.get_fluid_contents()