How to put all scenes with tilemaps in array

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DiFlector

I have an array of maps, I need to load all tilemaps into it, each of which is on a separate scene. How can I put all tilemaps from a folder into an array except this:

var maps := [preload("res://Map/map_00.tscn"), preload("res://Map/map_01.tscn")]
:bust_in_silhouette: Reply From: bloodsign

I’m no expert myself, but what I did was make an autoload(Global.gd) and put my array of maps there likeso:

Global.gd
    const maps = {
     "res://maps/map001.tscn",
     "res://maps/map002.tscn",
      #...etc
    }

Then on my scene where I need to load all of them(like a map navigation)
I simply load them and add them to the scene

func load_maps():
    for n in Global.maps:
       var pack = load(n)
       var instance = pack.instance()
       add_child(n) 

or load it into an array I could pass around:

var array = []  
func load_maps():
       for n in Global.maps:
          array.append(n) 

if I want to load all maps before storing them into an array:

var array = []  
func load_maps():
   for n in Global.maps:
      var pack = load(n)
      array.append(pack)