this post was submitted on 26 May 2024
27 points (100.0% liked)

Godot

5884 readers
1 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 1 year ago
MODERATORS
 

I have been trying to make receiving file paths really easy, with this method in an autoload:

func file_dialog_path(extentions:PackedStringArray = [], dialog_type:FileDialog.FileMode = FileDialog.FileMode.FILE_MODE_OPEN_FILE) -> String:
	var new_dialog:FileDialog = FileDialog.new()
	new_dialog.min_size = Vector2i(400, 400)
	new_dialog.access = FileDialog.ACCESS_FILESYSTEM
	new_dialog.file_mode = dialog_type
	for i in extentions:
		new_dialog.add_filter(i)
	get_tree().current_scene.add_child(new_dialog)
	new_dialog.popup_centered()
	var file_path:String = ""
	new_dialog.file_selected.connect( func receive_path(path:String):
		file_path = path
		print("file path from within the signal: ", path)
		return path)
	file_path = await new_dialog.files_selected
	print("this is the file now", file_path)
	
	#while file_path == "":
		#await get_tree().create_timer(0.1)
	return file_path

I commented out the while loop, as it froze the entire game when I do this.

I have tried this many times now, but the method always seems to get stuck somewhere. Right now, it gets stuck in the "receive path" function, where it will print the path, but not actually return. I am receiving the output from the file_dialog_path method like this:

var file:String = await file_dialog_path(["*.mml"], FileDialog.FileMode.FILE_MODE_SAVE_FILE)
print("This is the filepath for our level ", file)

Could anyone help me with this? The best idea I have right now would be to let that commented while loop run on a thread, but that seems unneccessarily difficult for such a simple problem.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] copycat@lemm.ee 9 points 5 months ago* (last edited 5 months ago) (1 children)

file_path = await new_dialog.files_selected

You probably want file_selected, not files. When the file mode is set to single file, then only file_selected signal is emitted, and when the file mode is set to multiple files, only files_selected is emitted. So if you use await files_selected when file mode is set to single file, then it will be stuck forever.

[โ€“] Smorty@lemmy.blahaj.zone 2 points 5 months ago* (last edited 5 months ago)

Thank you for helping me with this. It really was the file_selected signal.