Read entity definition details in control.lua?

Place to get help with not working mods / modding interface.
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

Read entity definition details in control.lua?

Post by jonatkins »

Is it possible to read details from entity definitions (from stock game/other mods) within control.lua?

Specifically, I'm trying to find out the range of radars placed on the map, so my mod can work correctly both with stock radars and modded ones with extended range.

From the stock game:

Code: Select all

  {
    type = "radar",
    name = "radar",
...
    max_distance_of_sector_revealed = 14,
    max_distance_of_nearby_sector_revealed = 3,
In control.lua, I've got access to both the name and type of the entity, so I know if it's a radar or not. However, I can't see a way of getting the other details. I also tried to see if I could access the data definitions directly (data.raw.entities.radar), but data isn't available in control.lua

Any suggestions?
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Read entity definition details in control.lua?

Post by Choumiko »

There is http://lua-api.factorio.com/latest/LuaE ... otype.html

which can be accessed through game.entity_prototypes["entity-name"] Not all details are available, but you can always make an api request.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Read entity definition details in control.lua?

Post by Nexela »

Take a look at https://mods.factorio.com/mods/sparr/expose-data-raw at how it works and Modify it to just loop through data.raw["radar"]
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

Re: Read entity definition details in control.lua?

Post by jonatkins »

Nexela wrote:Take a look at https://mods.factorio.com/mods/sparr/expose-data-raw at how it works and Modify it to just loop through data.raw["radar"]
Ugly, but clever - thanks!
Post Reply

Return to “Modding help”