Page 1 of 1

Invalid QualityID Error When Calling `get_max_wire_distance()` in Factorio 2.0

Posted: Wed Jan 14, 2026 12:21 pm
by hjfmailbox
Description:
I'm encountering a persistent error when calling the `get_max_wire_distance()` method on `LuaEntityPrototype` objects in Factorio 2.0. I've tried multiple approaches but all are failing with the same error.

Environment:
- Factorio Version: 2.0.72

Problem:
When calling `prototype:get_max_wire_distance()` (where prototype is a valid `LuaEntityPrototype` for an electric pole), I get the error:
Invalid QualityID: expected LuaQualityPrototype or string.

Old Code (Working in 1.1):

Code: Select all

-- Factorio 1.1 implementation
local prototype = game.entity_prototypes[name]
local reach = prototype.max_wire_distance
New Code Attempts (All Failing in 2.0):
I've tried the following approaches, all resulting in the same "Invalid QualityID" error:

1. No parameters:

Code: Select all

local prototype = prototypes.entity[name]
local reach = prototype:get_max_wire_distance()
2. Passing nil:

Code: Select all

local reach = prototype:get_max_wire_distance(nil)
3. Passing quality string:

Code: Select all

local reach = prototype:get_max_wire_distance("normal")
4. Passing valid LuaQualityPrototype:

Code: Select all

local quality = prototypes.quality["normal"] -- This is a valid LuaQualityPrototype object
local reach = prototype:get_max_wire_distance(quality)
Debug Information:
- `prototypes.quality` exists and contains valid quality prototypes
- `prototypes.quality["normal"]` returns `[LuaQualityPrototype: normal (quality)]`
- All calls to `get_max_wire_distance()` fail with the same error regardless of parameter type
- The entity prototype is valid (it's `big-electric-pole`)

Current Workaround:
I've implemented a temporary workaround using hardcoded default values, but this is not ideal:

Code: Select all

local default_distances = {
    ["small-electric-pole"] = 7.5,
    ["medium-electric-pole"] = 9,
    ["big-electric-pole"] = 18,
    ["substation"] = 18
}
local reach = default_distances[name] or 10
Question:
Has anyone successfully called `get_max_wire_distance()` in Factorio 2.0? What's the correct way to pass the QualityID parameter? Is there a change in the API that I'm missing?

Any help or insights would be greatly appreciated!

Re: Invalid QualityID Error When Calling `get_max_wire_distance()` in Factorio 2.0

Posted: Wed Jan 14, 2026 12:37 pm
by boskid
Lua says that if you call `prototype:get_max_wire_distance("normal")` (using ":") then it passes `prototype` as first parameter and "normal" becomes second parameter. Please use correct call (using "."):

Code: Select all

prototype.get_max_wire_distance("normal")
In that case you can also not provide quality since it defaults to "normal".

Re: Invalid QualityID Error When Calling `get_max_wire_distance()` in Factorio 2.0

Posted: Wed Jan 14, 2026 2:21 pm
by hjfmailbox
boskid wrote: Wed Jan 14, 2026 12:37 pm Lua says that if you call `prototype:get_max_wire_distance("normal")` (using ":") then it passes `prototype` as first parameter and "normal" becomes second parameter. Please use correct call (using "."):

Code: Select all

prototype.get_max_wire_distance("normal")
In that case you can also not provide quality since it defaults to "normal".
Thanks so much for catching my mistake with the method call! I really appreciate your help.