Can't access documented prototype property

Place to get help with not working mods / modding interface.
enraged_tomato
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Oct 26, 2024 8:21 pm
Contact:

Can't access documented prototype property

Post by enraged_tomato »

Hello everyone,

When I am trying to access max_distance_of_nearby_sector_revealed property of Radar prototype, I am getting this error
2065.603 Script @__ets-test__/control.lua:15: --- radar.prototype
2065.603 Script @__ets-test__/control.lua:16: "[LuaEntityPrototype: radar (radar)]"
2065.603 Script @__ets-test__/control.lua:17: --- radar.prototype.max_distance_of_nearby_sector_revealed
2065.694 Error MainLoop.cpp:1429: Exception at tick 1435795: The mod ET's test mod (2.0.0) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event ets-test::fire-test (ID 210)
LuaEntityPrototype doesn't contain key max_distance_of_nearby_sector_revealed.
stack traceback:
[C]: in function '__index'
__ets-test__/control.lua:18: in function <__ets-test__/control.lua:1>
I am trying to fix another mod and before 2.0 the mod was working fine.

Any help would be greatly appreciated~

Code example below:

Code: Select all

script.on_event("fire-test", function(event)
    local radar = nil

    for _, surface in pairs(game.surfaces) do
        for _, entity in pairs(surface.find_entities_filtered({ type = "radar" })) do
            radar = entity
            break
        end

        if radar then
            break
        end
    end

    log("--- radar.prototype ")
    log(serpent.block(radar.prototype))
    log("--- radar.prototype.max_distance_of_nearby_sector_revealed ")
    log(serpent.block(radar.prototype.max_distance_of_nearby_sector_revealed))
end)
User avatar
LCStark
Fast Inserter
Fast Inserter
Posts: 205
Joined: Thu Jan 28, 2021 5:04 pm
Contact:

Re: Can't access documented prototype property

Post by LCStark »

1. `surface.find_entities_filtered` returns `LuaEntity`.
2. `LuaEntity.prototype` gives you `LuaEntityPrototype`.

In 1.1.110, `LuaEntityPrototype` had a field `max_distance_of_nearby_sector_revealed`. Now that field is replaced by a function `https://lua-api.factorio.com/latest/cla ... r_revealed`.

But if you're just trying to access that range from the radar prototype, you don't need to find a radar entity in the world. Better to access the prototype directly. In 2.0, you do that by accessing `LuaPrototypes`, which is available as a global `prototypes`:

Code: Select all

local prototype = prototypes.entity["radar"]
local range = prototype.get_max_distance_of_nearby_sector_revealed()
enraged_tomato
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Oct 26, 2024 8:21 pm
Contact:

Re: Can't access documented prototype property

Post by enraged_tomato »

Hi LCStark,

First of all, the test code works with the function you mentioned, thank you!
LCStark wrote: Sun Oct 27, 2024 1:58 am In 1.1.110, `LuaEntityPrototype` had a field `max_distance_of_nearby_sector_revealed`. Now that field is replaced by a function `https://lua-api.factorio.com/latest/cla ... r_revealed`.
Does that mean that the documentation is not up to date? Since I still can find the old property in the radar prototype docs
LCStark wrote: Sun Oct 27, 2024 1:58 am But if you're just trying to access that range from the radar prototype, you don't need to find a radar entity in the world. Better to access the prototype directly. In 2.0, you do that by accessing `LuaPrototypes`, which is available as a global `prototypes`:

Code: Select all

local prototype = prototypes.entity["radar"]
local range = prototype.get_max_distance_of_nearby_sector_revealed()
True, thanks for the advice!
User avatar
LCStark
Fast Inserter
Fast Inserter
Posts: 205
Joined: Thu Jan 28, 2021 5:04 pm
Contact:

Re: Can't access documented prototype property

Post by LCStark »

enraged_tomato wrote: Sun Oct 27, 2024 7:54 pm Does that mean that the documentation is not up to date? Since I still can find the old property in the radar prototype docs
No, the docs are up to date. `RadarPrototype` still has that property, but you're not accessing the `RadarPrototype` directly. You're reading a `LuaEntityPrototype`, which used to have that property, but now has a `get_max_distance_of_nearby_sector_revealed()` method.
enraged_tomato
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Oct 26, 2024 8:21 pm
Contact:

Re: Can't access documented prototype property

Post by enraged_tomato »

LCStark wrote: Mon Oct 28, 2024 1:10 pm
enraged_tomato wrote: Sun Oct 27, 2024 7:54 pm Does that mean that the documentation is not up to date? Since I still can find the old property in the radar prototype docs
No, the docs are up to date. `RadarPrototype` still has that property, but you're not accessing the `RadarPrototype` directly. You're reading a `LuaEntityPrototype`, which used to have that property, but now has a `get_max_distance_of_nearby_sector_revealed()` method.
Ohh, I see... that's a bit confusing haha (I just wanted to fix some mods for 2.0 :D ) Thanks for the explanation~
Post Reply

Return to “Modding help”