Page 1 of 1

how to consistently detect when entities have electricity?

Posted: Tue Mar 12, 2019 9:19 pm
by dorfl
Filed this bug: viewtopic.php?f=7&t=67527

The GUI electricity bar oddness is not a big deal so I'm prepared for it to be not-a-bug, but from the Lua API perspective having LuaEntity .energy == .electric_buffer_size for a lamp with zero electricity available, and no internal generation capacity, is confusing.

Is there a better way than .energy > 0 to consistently detect when entities have power?

Re: how to consistently detect when entities have electricity?

Posted: Tue Mar 12, 2019 10:42 pm
by darkfrei
dorfl wrote:
Tue Mar 12, 2019 9:19 pm
Is there a better way than .energy > 0 to consistently detect when entities have power?
I don't know if it better, but I'm using here reading in power poles:

Code: Select all

function get_total_output_energy (output_counts)
  if output_counts then
    local energy = 0
    for input, value in pairs (output_counts) do
      energy = energy + value
    end
    return energy
  end
  return false
end
If it changes between ticks then you have power source, else no power was created.

Re: how to consistently detect when entities have electricity?

Posted: Sat Mar 16, 2019 11:31 am
by abregado
Try using this:
https://lua-api.factorio.com/latest/Lua ... ity.status
and
https://lua-api.factorio.com/latest/def ... ity_status

These are the statuses that show up in the tooltip now to tell you what is wrong with various machines.