how to consistently detect when entities have electricity?

Place to get help with not working mods / modding interface.
Post Reply
dorfl
Inserter
Inserter
Posts: 44
Joined: Mon May 28, 2018 12:49 am
Contact:

how to consistently detect when entities have electricity?

Post 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?

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: how to consistently detect when entities have electricity?

Post 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.

abregado
Former Staff
Former Staff
Posts: 282
Joined: Sat Aug 30, 2014 9:43 am
Contact:

Re: how to consistently detect when entities have electricity?

Post 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.

Post Reply

Return to “Modding help”