Page 1 of 1
How to Read Resource Richnesses
Posted: Wed Dec 14, 2016 11:30 pm
by Twisted6
Does anyone know how to read the map settings for resource richness for each of the resources (iron, copper, coal ect)?
Solved, answer:
Code: Select all
game.surfaces['nauvis'].map_gen_settings.autoplace_controls["iron-ore"].richness
Re: How to Read Resource Richnesses
Posted: Wed Dec 14, 2016 11:48 pm
by Nexela
game.print(game.player.surface.map_gen_settings.autoplace_controls["iron-ore"].richness)
Re: How to Read Resource Richnesses
Posted: Thu Dec 15, 2016 12:09 am
by Twisted6
Nexela wrote:game.print(game.player.surface.map_gen_settings.autoplace_controls["iron-ore"].richness)
That throws a nil value error on player, however game.print(game.surfaces['nauvis'].map_gen_settings.autoplace_controls["iron-ore"].richness) works. Thanks for the pointer.
Re: How to Read Resource Richnesses
Posted: Thu Dec 15, 2016 1:00 am
by Nexela
Sorry the example was for console use.
Also not sure where you are collecting this data at but using hard coded surfaces (i.e. surfaces['nauvis']) can cause undesired behavior on other surfaces from mods.
Re: How to Read Resource Richnesses
Posted: Thu Dec 15, 2016 1:35 am
by Twisted6
I'm unfamiliar with how the surfaces work but 'nauvis' is used in the base mod files. Maybe game.surfaces[1] would also work.
Re: How to Read Resource Richnesses
Posted: Thu Dec 15, 2016 3:10 am
by Nexela
game.surfaces[1] and surfaces['nauvis'] do the same thing (both refer to the nauvis surface)
How to handle it would be determined on where and how the code to get the data is used and or accessed.
I.E if you are getting the data during an event with a player or entity you can retrieve the surface from them.
script.on_event(defines.events.on_built_entity, function(event)
-- for the surface of the event entity
game.print(event.entity.surface.map_gen_settings.autoplace_controls["iron-ore"].richness)
-- for the surface of the player that built the entity
game.print(game.players[event.player_index].surface.map_gen_settings.autoplace_controls["iron-ore"].richness)
end)