Author Topic: Store map entities in a table automatically  (Read 173 times)

Yosha

  • Newbie
  • *
  • Posts: 37
    • View Profile
Store map entities in a table automatically
« on: July 31, 2018, 09:30:02 am »
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

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1139
    • View Profile
Re: Store map entities in a table automatically
« Reply #1 on: July 31, 2018, 10:18:06 am »
map:get_entities_by_type() is made for you.
Code: Lua
  1. local destinations = {}
  2. for destination in map:get_entities_by_type("destination") do
  3.   destinations[#destinations + 1] = destination
  4. end
  5.  

Yosha

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Store map entities in a table automatically
« Reply #2 on: August 01, 2018, 01:22:52 pm »
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 !
Code: [Select]
local destinations = {}
for destination in map:get_entities_by_type("destination") do
  destinations[#destinations + 1] = destination:get_name()
end
« Last Edit: August 01, 2018, 01:42:48 pm by Yosha »

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1139
    • View Profile
Re: Store map entities in a table automatically
« Reply #3 on: August 01, 2018, 03:12:23 pm »
Thanks ^^
Then you have a table of destination names and not a table of destinations.