0 votes

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..

in Engine by (225 points)

1 Answer

0 votes

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.

by (51 points)
edited by
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.