Page 1 of 1

[Rseding91] LuaFluidBoxPrototype issues

Posted: Tue Jun 23, 2020 5:31 am
by theawesomeawe1
entity.fluidbox.get_prototype(index) should return the fluidbox prototype used by the fluidbox that can be accessed by entity.fluidbox[index]. Instead, it returns the nth entity prototype's fluidbox definition (eg, if index = 1, then it returns the first fluidbox defined in the entity prototype). However, it is still limited by the number of fluidboxes actually present in game, given by #entity.fluidbox, which for all vanilla assembler recipes, is less than the number of fluidbox prototypes.

Steps to recreate: place an assembling-machine-3, set it's recipe to fill lubricate barrel, hover over it, and execute:

/c local ent = game.player.selected
game.print(ent.fluidbox.get_prototype(1).production_type)

The string printed is "input"

Change assembler's recipe to "empty lubricant barrel" and execute the same code again.

The string printed is still "input", even though the empty barrel recipe uses the output fluidbox of the assembling-machine-3 prototype.

In both cases, "ent.fluidbox.get_prototype(2).production_type" gives an error because in "get_prototype(2)" the 2 is out of bounds as the assembler's #entity.fluidbox is 1.

What I expect to happen: "get_prototype(index)" should return the prototype used by the fluidbox referenced by "fluidbox[index]"

[1.0.0] API Bug: LuaEntityPrototype.fluid_energy_source_prototype.fluid_box has incorrect index.

Posted: Sun Aug 16, 2020 12:28 pm
by Creidhne
Description

I am using the API to get the index of the LuaFluidBoxPrototype used as fuel input in a LuaEntityPrototype (more precisely a boiler prototype). I do it like this:

Code: Select all

local index = entity_prototype.fluid_energy_source_prototype.fluid_box.index
However it does not match the right fluidbox in LuaEntityPrototype.fluidbox_prototypes (index in fluid_energy_source_prototype seems to always be 1).

Example / Steps to reproduce
  1. Download & enable the gas-boiler mod.
  2. Start a new game.
  3. Use the following commands to read some data in fluid_energy_source_prototype

    Code: Select all

    /c game.print(game.entity_prototypes["gas-boiler"].fluid_energy_source_prototype.fluid_box.index)
    
    1
    
    /c game.print(game.entity_prototypes["gas-boiler"].fluid_energy_source_prototype.fluid_box.production_type)
    
    none
    
  4. Use the following command to dump some data about the entity's fluidboxes:

    Code: Select all

    /c for index,fluidbox in ipairs(game.entity_prototypes["gas-boiler"].fluidbox_prototypes) do game.print(tostring(index) .. ": " .. fluidbox.production_type) end
    
    1: input-output
    2: output
    3: none
    
  5. The index returned in step 3 matches the water's input of the boiler, instead of the fuel input (which is at index 3).
The proposed mod is just the simplest one I have found to make a minimal example, but I've also observed it with other fluid powered boilers in another mod (so it doesn't seem mod specific).

Re: [1.0.0] API Bug: LuaEntityPrototype.fluid_energy_source_prototype.fluid_box has incorrect index.

Posted: Thu Aug 27, 2020 7:23 pm
by Rseding91
I don't know if this has a nice fix. The whole mapping of runtime fluidboxes to the prototype they originated from is kind of just 'lost' because mostly the game doesn't care about it. It uses the prototype to make the fluidbox instance and then after that it mostly doesn't care about the prototype.

Mapping a runtime fluidbox back to it's prototype kind of just doesn't work.

Re: [Rseding91] LuaFluidBoxPrototype issues

Posted: Thu Aug 27, 2020 7:40 pm
by Creidhne
Thanks for the answer.

Personally I don't mind the issue to not be really fixed. I just want to generate a pseudo-recipe: boiler X takes fluid A as input, outputs fluids B, and uses fluid C as fuel (with possibly "any fluid" if there are no filters on the fluidbox). If you have any suggestion to retrieve that from the existing API, or just add something that allow me to do that, I'll be a happy modder.

Re: [Rseding91] LuaFluidBoxPrototype issues

Posted: Thu Aug 27, 2020 7:48 pm
by theawesomeawe1
Thank you for the answer.

That makes sense to not have runtime fluidboxes tied to the prototype they originated from.

Is it possible for a runtime fluidbox to have read only access to its "pipe-connections" (the array of "FluidBoxConnection") parameters? I'm not sure how the game deals with connecting fluidboxes but a fluidbox should store its possible connecting positions somewhere, right? Is it possible to make that a read only parameter for a fluidbox?