FileDialog only shows up once but I want it to show up if a file couldnt be found.

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

here is a link to the code : Legobet88 🀄 Trustworthy Agen Situs Slot Online Bet88 Terpercaya Ter- Gacor Hari Ini 2024

func check_all_files_exist():
	var directory =
	var file =
	if !directory.dir_exists(docs + "/Open Mod Manager"):
	if !file.file_exists(OMM_Folder + "/OMM.ini"): + "/OMM.ini",File.WRITE)
	explorer.popup_centered(get_viewport_rect().size / 2)
func set_ini_info(path : String):
	var config =
	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) + "/OMM.ini")
			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.

:bust_in_silhouette: Reply From: MisterMano

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.

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

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

Dragon20C | 2021-08-25 06:36

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 ?

MisterMano | 2021-08-25 14:56

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.

Dragon20C | 2021-08-25 15:12

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

MisterMano | 2021-08-25 17:01