Store map entities in a table automatically

Started by Yosha, July 31, 2018, 09:30:02 AM

Previous topic - Next topic
Hello !! Long time no see !

I'm wondering if it was possible create a table with map entities ?
Here is my need :
I want to create some npc randomly on a map, but, I want those npc to be created on random destinations already on the map. I found how to do, but I have to make a table with all destination manually, and I wanted to know if it was a possibility to automatically generate a table with all map destinations (it could be usefull if the map had 50 or more destinations)

I think that using the map data file could be a solution but I don't see how to do it... (maybe with parsing the map entities corresponding to a destination ?)

Thanks in advance for solutions

map:get_entities_by_type() is made for you.
Code (lua) Select

local destinations = {}
for destination in map:get_entities_by_type("destination") do
  destinations[#destinations + 1] = destination
end

August 01, 2018, 01:22:52 PM #2 Last Edit: August 01, 2018, 01:42:48 PM by Yosha
Thanks a lot, Grand Master of Solarus ! It was more easy than I expected !!  ;D
I just have to add get_name()  to make it work !
local destinations = {}
for destination in map:get_entities_by_type("destination") do
  destinations[#destinations + 1] = destination:get_name()
end

Thanks ^^
Then you have a table of destination names and not a table of destinations.