0 votes

I'm having trouble loading a file path into my save system, _file_selected( String path )

What I am doing is saving the path to the file in a var called filepath.
I then use this path in the savegame function to open a file

(AKA File.new().open(filepath,File.WRITE))

However I am having trouble getting the filepath when loading/opening the file. Save mode works, but not MODEOPENFILE

extends Control

var num = 0
var filepath
#Nodes
var file #The name of the FileDialog, Confusing I know.

func _ready():
    file = get_node("file")
    pass
#File node
func display_file(filetype):
    file.set_hidden(false)
    file.set_mode(filetype)

func _on_file_file_selected( path ):
    filepath = path 
    if file.MODE_SAVE_FILE:
        print("save")
        print("Filename: "+str(file.get_current_file()))

    elif file.MODE_OPEN_FILE:
        print("load")
        print("Filename: "+str(file.get_current_file()))
    else:
        print("Error, Could not load/Save")
    print(path)

#Click button
func _on_click_pressed():
    num += 1
    get_node("click").set_text(str(num))

#Save and Load buttons
func _on_save_pressed():
    display_file(file.MODE_SAVE_FILE)

func _on_load_pressed():
    display_file(file.MODE_OPEN_FILE)

I am using the current stable branch 2.1.3

asked Jun 29, 2017 in Engine by lavaduder (263 points)

Please log in or register to answer this question.

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.