Page 1 of 1

Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 7:53 pm
by Crimso
Hello Factorio Forum!

I am Crimso, author of an accessibility mod with the goal of making Factorio completely accessible to the blind.

I am running into an issue where when I get the electric_network_statistics value of an electric pole, the output_counts and input_counts attributes are returning empty dictionaries. I am determining they are empty using both the # operator, and attempting to iterate through the entire dictionary with the pairs function.

I have also tried get_output_count for "steam-engine" "solar-panel" etc with no results.

Perhaps I am misunderstanding something fundamental, or perhaps a bug has been discovered? Any help would be greatly appreciated!

Re: Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 8:29 pm
by Qon
You didn't post the code that you tried.

Re: Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 8:58 pm
by Crimso
local ent = players[pindex].tile.ents[1]
result = ent.name
result = result .. " " .. ent.type
if ent.type == "electric-pole" then
result = result .. #ent.neighbours.copper
if next(ent.electric_network_statistics.input_counts) == nil then
print("Abandon all hope ye who enter")
end

for i, v in ipairs(ent.electric_network_statistics.input_counts) do
print("Producer " .. i .. " " .. v)
end
end
if ent.prototype.electric_energy_source_prototype ~= nil and ent.is_connected_to_electric_network() == false then
result = result .. "Not Connected"
end


Hope this helps!

Re: Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 9:13 pm
by Gweneph
I have the same issue in vanilla. Maybe we need to initialize something? Here's a one liner that I ran on a map with just a solar panel, small electric pole, and radar.

Code: Select all

/c game.player.print(#game.player.surface.find_entities_filtered{name="small-electric-pole"}[1].electric_network_statistics.input_counts)
I did the same thing for output counts. They're both empty.

Re: Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 9:40 pm
by Qon
Crimso wrote:
Sun Jun 12, 2022 8:58 pm
Hope this helps!
Not as much as if you indented properly and used code tags. Your code doesn't run.
players, print and pindex are not defined. You get error messages for that. Edit: print is defined, but you probably meant game.print or game.player.print if you want it printed in game
You never printed result so you don't see it.
Don't use ipairs for dicts. Use pairs for dicts.

Mouse over to select an entity and run this code in console (prefix "/c ")

Code: Select all

local ent = game.player.selected
local result = ent.name
result = result .. " " .. ent.type
if ent.type == "electric-pole" then
    result = result .. #ent.neighbours.copper
    if next(ent.electric_network_statistics.input_counts) == nil then
        game.print("Abandon all hope ye who enter")
    end

    for i, v in pairs(ent.electric_network_statistics.input_counts) do
        game.print("Producer " .. i .. " " .. v)
    end
end
if ent.prototype.electric_energy_source_prototype ~= nil and ent.is_connected_to_electric_network() == false then
    result = result .. "Not Connected"
end
game.print(result)

Re: Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 9:44 pm
by Qon
Gweneph wrote:
Sun Jun 12, 2022 9:13 pm
I have the same issue in vanilla. Maybe we need to initialize something? Here's a one liner that I ran on a map with just a solar panel, small electric pole, and radar.

Code: Select all

/c game.player.print(#game.player.surface.find_entities_filtered{name="small-electric-pole"}[1].electric_network_statistics.input_counts)
I did the same thing for output counts. They're both empty.
Use table_size() to check size of dicts. You can't use # for that.
Also, use game.player.selected and hover over a power pole to test code easier without having to start a world with only 1 electric pole.

Re: Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 9:48 pm
by Crimso
my code is indented heavily because it is part of 3000 lines of code. It is printing to the command line prompt I am using to debug the program. I apologize if my formatting is wrong, I am blind and cannot see it. I used pairs initially and got the same result. Thanks for the help ;)

Re: Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 10:01 pm
by Crimso
I tried your code and it didn't work. [Moderated by Koub : Please be civil, and don't start fights on this forum]

Edit: More specifically if anyone has had luck getting the output or energy producers tab of the electrical network statistics, I would be very grateful for a push in the right direction.

Edit2: If anyone else is having similar issues, make sure that the network in question has both producers and drainers on the electrical system or there will not be any contents in the input or output attributes.

Re: Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 10:40 pm
by Qon
Crimso wrote:
Sun Jun 12, 2022 9:48 pm
Thanks for the help ;)
Np :)
Crimso wrote:
Sun Jun 12, 2022 10:01 pm
I tried your code and it didn't work.
Why would you post that after?
And you didn't say what you tried. I got output on my computer because I tested it, if you want help then ask questions don't just say that working solutions don't work for you.
[Moderated by Koub : Response to a moderated content]

Re: Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 11:24 pm
by FuryoftheStars
[Moderated by Koub : Response to a moderated content]

[Moderated by Koub : Response to a moderated content]. While you did say that you were working on something to make the game more accessible to the blind, you didn't say that you yourself were, so Qon had no way of knowing that you couldn't see the formatting.

[Moderated by Koub : Response to a moderated content]

Anyway...
Crimso wrote:
Sun Jun 12, 2022 10:01 pm
I tried your code and it didn't work.
I gave Qon's code a try in exactly the manor they said to use it, and it works for me.

Re: Electric Network Statistics returning empty Dictionaries

Posted: Sun Jun 12, 2022 11:31 pm
by lyvgbfh
[Moderated by Koub : Response to a moderated content]
Crimso wrote:
Sun Jun 12, 2022 8:58 pm
local ent = players[pindex].tile.ents[1]
Can you clarify what player.tile and player.tile.ents is? The code that sets this would show well enough.

I'm able to print simple stats mousing over a wooden power pole and running the following:

Code: Select all

/c local ent = game.player.selected for k, v in pairs(ent.electric_network_statistics.input_counts) do game.print(k .. " " .. v) end
the output of which is
fast-inserter 10371.333065987

Re: Electric Network Statistics returning empty Dictionaries

Posted: Mon Jun 13, 2022 12:11 am
by Qon
[Moderated by Koub : Response to a moderated content]

Re: Electric Network Statistics returning empty Dictionaries

Posted: Mon Jun 13, 2022 12:29 am
by lyvgbfh
[Moderated by Koub : Response to a moderated content]

Re: Electric Network Statistics returning empty Dictionaries

Posted: Mon Jun 13, 2022 12:40 am
by Qon
[Moderated by Koub : Response to a moderated content]

Re: Electric Network Statistics returning empty Dictionaries

Posted: Mon Jun 13, 2022 6:17 am
by Koub
[Koub] I know this forum is on the Internet, so it's expected somehow that people call each others names and stuff, but that won't be under my watch. I removed all the fighting bits, and tried letting the good stuff. I advise everybody in here not to reactivate the fire.