Multiply loads bug

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Serenade
:warning: Old Version Published before Godot 3 was released.

Hey!
I have made load func, where it finds files(TSCN) and then loads them when you press the button, but it loads them on scene every time i press load button, so how can i make it recognise that it already loaded them, so that it doesnt load them on every tie you press the button? Heres my code…

var dir = Directory.new()
var folder = ("res://SAVES_folder")

if dir.open(folder) == OK:
	dir.list_dir_begin()
	var FILES = dir.get_next() 
	while FILES != "":
		if not dir.current_is_dir() :
			var file_path = folder + "/" + FILES 
			print(file_path)
			var path = load(file_path) #shortcut for the filepath combo
			var obj = path.instance() #instance the shortcut to load
			obj.get_name()
			add_child(obj)
		FILES = dir.get_next()
	dir.remove(FILES)

I tried to make a counter, when there have been scenes loaded, it adds +1 and then if loaded scenes >1, do not load and such, but didnt work…

:bust_in_silhouette: Reply From: Anutrix

I am not sure but this seems to be logical problem(unless I am mistaken). You can try following (untested python derived )simple code instead of add_child(obj):

var filesAdded      #Array to store filepath of added files
if current not in fileadded:
    filesAdded.append(name)
    add_child(obj)

Take a look at my file copy finder written in python for reference.
Also I guess you to take a look at Python book like this if you haven’t yet.