how to properly use lineEdit input?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GRG
:warning: Old Version Published before Godot 3 was released.

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 :slight_smile:

:bust_in_silhouette: Reply From: ingo_nikot

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
else:
#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
else:
	#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 :wink: