Page 1 of 1
[2.0.22] get_flow_count returns 0 for entities with quality
Posted: Thu Nov 28, 2024 4:39 pm
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.
Re: [2.0.22] get_flow_count returns 0 for entities with quality
Posted: Thu Nov 28, 2024 6:25 pm
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.
Re: [2.0.22] get_flow_count returns 0 for entities with quality
Posted: Thu Nov 28, 2024 7:14 pm
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.