0 votes

I know there is a way to implement a save function in GDscript using the file.new but I can't seem to find a way or tutorial or anything if it's even possible. I can't find any way to use file.new in visual script or anything. I can't switch to GDscript because I have already put in a lot of code for my game and I don't know it. Please if someone knows how to implement a save system using Visual Script. (For a clicker game)

in Engine by (15 points)

2 Answers

+1 vote
Best answer

You'll have to use an autoload/singleton gdscript and call save and load functions from the visual script. Here are the save and load functions

func save_game_cfg(data, file_name: String = "Saved Data", section_name: String = "Section", key_name: String = "Key"):
    var save_dir = "user://" + file_name + ".cfg"
    var configFile = ConfigFile.new()
    configFile.set_value(section_name, key_name, data) configFile.save(save_dir)

func load_game_cfg(file_name: String = "Saved Data", section_name: String = "Section", key_name: String = "Key"):
    var load_dir = "user://" + file_name + ".cfg"
    var configFile = ConfigFile.new()
    var err = configFile.load(load_dir)
    if err == OK:
        var data = configFile.get_value(section_name, key_name)
        return data
by (3,247 points)
selected by
0 votes

I'm not familiar with VisualScript, but you should be able to use a ConfigFile for this.

by (111 points)

it's not possible to access the Config File stuff in visual script. You can't do anything with files in visual script

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 Frequently asked questions and 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 [email protected] with your username.