0 votes

I'm using a LineEdit input to import images while the app is running, if the user inputs an invalid path (asdaf) I get an error:
- No Loader found for resource: asdaf
Can it cause bugs? if so how can i avoid it? Also how to limit the input to images only? (if possible without using FileDialog)

thanks for your time :)

in Engine by (12 points)

1 Answer

0 votes

if so how can i avoid it?

check if the file exists before opening it, you can use:

var file = File.new()
if file.file_exists(path_to_file):
#do stuff with the file here
#say user file not found

Also how to limit the input to images only?

var allowed_file_ext =  ["jpg","png","bmp"]
var file_name = "foo.jpg"
var ext = file_name.split(".")[-1] #split the filename and returns array. [-1] will give you the last item of the array, in this case "jpg"
if ext in allowed_file_ext: #jpg is an element of allowed_file_ext
    #valid extension
    #not valid file extension

be aware that file_name.split(".")[-1] could throw an error if the user inputs a filename without file extension. but i think you are able to change the code accordingly ;)

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