Page 1 of 1

Read entity definition details in control.lua?

Posted: Fri Sep 16, 2016 6:31 pm
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?

Re: Read entity definition details in control.lua?

Posted: Fri Sep 16, 2016 6:34 pm
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.

Re: Read entity definition details in control.lua?

Posted: Fri Sep 16, 2016 7:58 pm
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"]

Re: Read entity definition details in control.lua?

Posted: Fri Sep 16, 2016 8:09 pm
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!