0 votes

here is a link to the code : https://pasteall.org/uVLZ

func check_all_files_exist():
    var directory = Directory.new()
    var file = File.new()
    if !directory.dir_exists(docs + "/Open Mod Manager"):
        directory.make_dir(OMM_Folder)

    if !file.file_exists(OMM_Folder + "/OMM.ini"):
        file.open(OMM_Folder + "/OMM.ini",File.WRITE)
        file.close()

    explorer.popup_centered(get_viewport_rect().size / 2)

func set_ini_info(path : String):
    var config = ConfigFile.new()
    var err = config.load(OMM_Folder + "/OMM.ini")
    if err == OK:
        #if !config.has_section_key("OMM", "Fallout4_Dir"):
        if check_valid_folder(path):
            config.set_value("OMM", "Fallout4_Dir", path)
            config.save(OMM_Folder + "/OMM.ini")
        else:
            print("false")
            explorer.popup_centered(get_viewport_rect().size / 2)
        # Save the changes by overwriting the previous file

fyi the filedialog is called explorer in my case.
I first open it in the first function and then in the second function I call another function if the filedialog doesnt open up a valid folder, but it doesnt open it, any clues why its not opening or maybe thats how its supposed to work.

Godot version 3.3.2
in Engine by (164 points)

1 Answer

0 votes

The way you wrote the post makes it kinda hard to understand what exactly is the problem. Title says you want the dialog to show if the file couldn't be found, which should be a simple case of calling the function in the portion that deals with the error.

"but it doesn't open it, any clues why its not opening": not opening what, the dialog? The function? The file?

Reading the code, I noticed this:

  • First, in the check_all function, you should use ConfigFile instead of File, since you're looking for a .ini file. So, use something like if config.load(OMM + "/OMM.ini") != OK: Do note that a File.WRITE saves the data in a human unreadable manner, so you can't manually edit it.

  • Second, note that you didn't put an else on the check folder function's if. Not strictly necessary, but it makes the logic clearer

If your problem is that your check folder function is always returning false, in other words, never finding the file you're looking for, the first thing I would look into is whether the path variable has the proper string you're expecting. Put a print(path) at the start of that check function and compare it to your docs or OMM_folder variables.

by (294 points)

Pretty much when I call explorer.popupcentered(getviewport_rect().size / 2) in the second function it doesnt open up the filedialog

EDIT: I added a yield(gettree().createtimer(0.1), "timeout")
and that seemed to fix it, I assume it closed and opened in the same frame creating this unique issue.

Ah, so that was the actual problem. Where did you add that yield? Right before calling it on the set_ini_info?

It looks like that it wasn't creating the popup dialog because it already existed and was visible, which that yield fixes. Can you experiment with setting this instead of calling the yield: explorer.visible = false ?

I put the yield before I open it again and I visible actually says is true meaning you can see it but no, no you can't.

What I meant is for you to turn the explorer invisible, set the property visible to false, instead of using the yield function, and see if that works or not.

#if false...
#yield(get_tree())
explorer.visible = false #turn it invisible before calling the popup function
explorer.popup_centered(get_viewport_rect().size / 2)

If it doesn't work, well, at least your solution with yield works.

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 Frequently asked questions and 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 [email protected] with your username.