LuaEntity does not contain fluid_boxes

Place to get help with not working mods / modding interface.
Kamikazimon
Burner Inserter
Burner Inserter
Posts: 5
Joined: Fri Oct 25, 2024 4:01 pm
Contact:

LuaEntity does not contain fluid_boxes

Post by Kamikazimon »

Hello,

I am currently trying to add a furnace-type entity to my mod and accessing it's fluid_boxes property. I have created this entity in one lua file:

Code: Select all

local cooling_tower = table.deepcopy(data.raw["furnace"]["electric-furnace"])
cooling_tower.type = "furnace"
cooling_tower.name = "cooling-tower"
cooling_tower.icon = graphics.."icons/cooling-tower.png"
cooling_tower.icon_size = 32
cooling_tower.flags = {"hide-alt-info", "placeable-player", "player-creation"}
cooling_tower.minable = {hardness = 0.2, mining_time = 0.5, result = "cooling-tower"}
cooling_tower.max_health = 500
cooling_tower.corpse = "medium-remnants"
cooling_tower.resistances = 
{
  {
    type = "fire",
    percent = 70
  }
}
cooling_tower.collision_box = {{-1.5, -1.5}, {1.5, 1.5}}
cooling_tower.selection_box = {{-1.5, -1.5}, {1.5, 1.5}}
cooling_tower.drawing_box = {{-1.5, -1.5}, {1.5, 1.5}}
cooling_tower.fluid_boxes = 
{
  {
    production_type = "input",
    volume = 1000,
    pipe_covers = pipecoverspictures(),
    pipe_picture = nil,
    pipe_connections = {
      {position = {-1, -1}, flow_direction = "input", direction = defines.direction.west},
      {position = {-1, -1}, flow_direction = "input", direction = defines.direction.north},
      {position = {1, -1}, flow_direction = "input", direction = defines.direction.north},
      {position = {1, -1}, flow_direction = "input", direction = defines.direction.east}
    },
    secondary_draw_orders = { north = -1 }
  },
  {
    production_type = "output",
    volume = 1000,
    pipe_covers = pipecoverspictures(),
    pipe_picture = nil,
    pipe_connections = 
    {
      {position = {-1, 1}, flow_direction = "output", direction = defines.direction.west},
      {position = {-1, 1}, flow_direction = "output", direction = defines.direction.south},
      {position = {1, 1}, flow_direction = "output", direction = defines.direction.south},
      {position = {1, 1}, flow_direction = "output", direction = defines.direction.east}
    },
    secondary_draw_orders = { north = -1 }
  }
}
cooling_tower.fluid_boxes_off_when_no_fluid_recipe = false
cooling_tower.source_inventory_size = 0
cooling_tower.result_inventory_size = 0
cooling_tower.crafting_categories = {"water-cooling"}
cooling_tower.energy_usage = "200kW" -- will be increased during active water cooling
cooling_tower.graphics_set =
{
  animation =
  {
    layers =
    {
      {
        filename = graphics.."entity/cooling-tower/cooling-tower.png",
        width = 308, height = 310,
        shift = {0.695, -0.66},
        scale = 0.505
      }
    },
    {
      {
        filename = graphics.."entity/cooling-tower/cooling-tower-shadow.png",
        width = 430, height = 310,
        shift = util.by_pixel(52, -21),
        scale = 0.5,
        draw_as_shadow = true,
        flags = {"shadow"}
      }
    }
  },
  working_visualisations = 
  {
    {
      filename = graphics.."entity/cooling-tower/cooling-tower-light.png",
      scale = 0.505,
      width = 308, height = 310,
      shift = {0.695, -0.66},
      tint = {r = 1, g = 0, b = 0},
      draw_as_light = true,
      priority = "extra-high",
      flags = {"light"}
    }
  },
  {
    {
      filename = graphics.."entity/cooling-tower/cooling-tower-glow.png",
      scale = 0.505,
      width = 308, height = 310,
      shift = {0.695, -0.66},
      tint = {r = 1, g = 0, b = 0},
      draw_as_light = true,
      priority = "extra-high",
      flags = {"light"}
    }
  }
}

data:extend({cooling_tower})
When place this entity-name "cooling-tower" I want the entity to be added to an array of other entities of this types called "cooling-tower-entities". Hence, I added this to my control.lua:

Code: Select all

script.on_event({ defines.events.on_built_entity, defines.events.on_robot_built_entity, defines.events.script_raised_built, defines.events.script_raised_revive }, function(event)
    local entity = event.created_entity or event.entity
    if entity and entity.valid and entity.name == cooling_tower_name then
        cooling_tower_placed(entity)
    end
end)
The "cooling_tower_placed(entity)" function looks like this:

Code: Select all

function cooling_tower_placed(entity)
    table.insert(cooling_tower_entities, entity)
    game.print(#cooling_tower_entities)
    game.print(entity.name)
    game.print(entity.type)
    game.print(entity.fluid_boxes[1].amount)
end
When I place the entity-cooling tower, I get this in my output:

Code: Select all

1
cooling-tower
furnace
followed by this error message:
LuaEntity doesn't contain key fluid_boxes
. But it should, right? The entity seemingly gets added correctly to the array "cooling-tower-entities", and I can access it's name and type. Does anyone know, what I am doing wrong? I am using Factorio Space Age 2.0.15.

Any help is appreciated!
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 427
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: LuaEntity does not contain fluid_boxes

Post by Stringweasel »

You're not using the correct name. It's called `entity.fluidbox`

https://lua-api.factorio.com/latest/cla ... l#fluidbox
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
Kamikazimon
Burner Inserter
Burner Inserter
Posts: 5
Joined: Fri Oct 25, 2024 4:01 pm
Contact:

Re: LuaEntity does not contain fluid_boxes

Post by Kamikazimon »

Ah, sorry for not noticing this! Thank you!
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 427
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: LuaEntity does not contain fluid_boxes

Post by Stringweasel »

No worries. The fluidbox naming in the API is quite inconsistent :D
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
Post Reply

Return to “Modding help”