[2.0.22] get_flow_count returns 0 for entities with quality

Bugs that are actually features.
0n0w1c
Inserter
Inserter
Posts: 29
Joined: Sat Sep 09, 2023 1:43 pm
Contact:

[2.0.22] get_flow_count returns 0 for entities with quality

Post by 0n0w1c »

Code: Select all

function get_usage(pole)
    if not (pole and pole.valid and pole.type == "electric-pole" and pole.electric_network_statistics) then
        return 0
    end

    local stats = pole.electric_network_statistics
    local total_usage = 0

    for prototype_name, _ in pairs(stats.input_counts) do
        local flow = stats.get_flow_count {
            name = prototype_name,
            precision_index = defines.flow_precision_index.five_seconds,
            count = false,
            category = "input"
        }

        total_usage = total_usage + flow
    end

    return total_usage * 60 -- Convert from per tick to per second
end
flow returns 0 for entities with quality.

For instance, if I place a single normal radar, 300kW is returned. Replace it with a radar with quality other than normal, 0kW is returned.

In stepping through, the "radar" prototype name is returned but the flow is 0 if higher than normal quality.
0n0w1c
Inserter
Inserter
Posts: 29
Joined: Sat Sep 09, 2023 1:43 pm
Contact:

Re: [2.0.22] get_flow_count returns 0 for entities with quality

Post by 0n0w1c »

Code: Select all

function get_production(pole)
    if not (pole and pole.valid and pole.type == "electric-pole" and pole.electric_network_statistics) then
        return 0
    end

    local stats = pole.electric_network_statistics
    local total_production = 0

    for prototype_name, _ in pairs(stats.output_counts) do
        local flow = stats.get_flow_count {
            name = prototype_name,
            precision_index = defines.flow_precision_index.five_seconds,
            count = false,
            category = "output"
        }

        total_production = total_production + flow
    end

    return total_production * 60 -- Convert from per tick to per second
end
And I have this function for the production.

I have a modded entity that separates two electric networks, one network contains the usage, the other network the production.
The modded entity has two electric poles that I am using to gather the electric stats.

Something odd occurs when taking a look at different entities attached to the usage network. Most normal entities show the expected minimum usage when placed and the production stats match the usage.

Place an inserter and the usage stats are as expected, however the production stats then shows as 0. The electric network gui shows the correct numbers, it seems to be get_flow_stats can produce unexpected results for both input and output.

Edit: The output flow stats are 0 for entities with a quality higher than normal.
Edit 2: Tested with 2.0.23, same results.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15007
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.22] get_flow_count returns 0 for entities with quality

Post by Rseding91 »

Thanks for the report however this is correct. You did not give a quality so it defaulted to normal. You most provide the quality in the ID definition similar to other places that accept Id with quality.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Not a bug”