0 votes

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")]
Godot version latest
in Engine by (14 points)

1 Answer

0 votes

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) 
by (334 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.