So I would like to learn how to make it so in my game you can have save files, those files being saved to the players computer considering I dont have a datastore.
So my questions are: Is this even possible? If so how can I do it?
As I am relatively new to Godot the more detail you can go into would be appreciated.

Thanks!
~ Froyo ~

    Frodev Is this even possible?

    What kind of question is that? Of course it is! Games have ALWAYS saved data in files. Godot has a special folder just for user data, the location depends on OS (platform). this folder can be accessed with user://, as oposed to res:// which contains compressed game data.
    https://docs.godotengine.org/en/stable/tutorials/io/data_paths.html

    You should read the docs.

    Here's the oficial documentation on saving games. This can be applied to any form of data, it doesn't have to be always nodes, you can save just the player data and update it on only the player and certain objects when the game starts, like in diablo.

    https://docs.godotengine.org/en/stable/tutorials/io/saving_games.html

      Jesusemora
      Ok so really helpful so far!
      I have but one questions, if I wish to save data to a file, how can I create the file to begin with? Thanks!

      DaveTheCoder
      Is configFile good for storing player data?

      Other than that Im trying to create a text file in the user documents with the name of a certain variable I have called gameName.
      But anyhow I cant figure it out. So this is my current code, no errors, and it prints "created", but nothing appears in my files which gives me reason to believe I have to parent it or something:

      `
      func saveFileFunc(File,_Difficulty) :
      var parentFilePath = "user://Documents"

      if not FileAccess.file_exists(parentFilePath+"/"+gameName+".txt") :
      	print('creating')
      	var GameFile = FileAccess.open(parentFilePath,FileAccess.WRITE)
      	
      	if GameFile != null :
      		print('created')
      		GameFile.store_string('Game file thing')
      		GameFile.close()
      	else :
      		print('failed')
      		return
      else :
      	print('Storage file already exists')

      `

      DaveTheCoder
      Ok did that but it didnt work, Im probably doing something wrong to be honest, anyhow heres what I have currently. See anything wrong with it that could be throwing it off?
      `

      data

      func saveFileFunc(File,_Difficulty) :
      var parentFilePath = "user://Documents"

      if not FileAccess.file_exists(parentFilePath+"/"+gameName+".txt") :
      	print('creating')
      	
      	var GameFile := FileAccess.open(parentFilePath + "/" + gameName + ".txt", FileAccess.WRITE)
      
      	if GameFile != null:
      		print("Created game file successfully!")  # Clear message for success
      
      		GameFile.store_string("Game file thing")
      		GameFile.close()
      	else:
      		print("Failed to create game file:")  # Clear message for failure
      		print(FileAccess.get_open_error())  # Get detailed error message

      `

      Do I need to set something in Project Settings? I feel like it could be something simple like that

      DaveTheCoder
      Oh sorry! I shouldve thought to answer these!
      gameName is a string, which is as of now "UntitledGame"
      The output is:

      creating
      Failed to create game file:
      7

      The result of .get_open_error() is 7,
      If you need anything else please feel free to ask!

      DaveTheCoder You were right, documents doesnt exist! After removing the documents part it works!
      Ill ask if I have more questions!

      DaveTheCoder
      Ok quick question, once this file is created, if the path is: "user://"+ "gameName" + ".txt", where does it appear on my PC cause I cant find it

      DaveTheCoder Ok so yeah that makes sense, anyhow Im struggling to figure out how to make it go to a path outside of that file and lets say put it in to documents (documents being the folder that comes built in to a PC most of the time).
      Thank you btw

      DaveTheCoder Could you show me an example? Im kinda bad at figuring these things out on my own as youll have noticed

      Using absolute paths here is not a very good idea. Just use user:\\ provided by Godot. If you want to know what's its absolute path - ask the engine:

      print(ProjectSettings.globalize_path("user://"))

        DaveTheCoder You didn't read the preceding posts.

        Just skimmed over them, but using absolute paths from a game (engine) is something you never want or need to do.

        DaveTheCoder Are you intentionally acting obtuse?

        No, why would I want to do that? I'm just quite busy lately so forgive me if my attention is a bit floaty.

        That said, I still can't catch why absolute paths even entered the conversation.

        xyz
        I have a question, if I was to save data with "user://" it says that it is saved to the godot folder on the users computer, but what if someone gets my game and just like dont have godot, where does this path lead?

        • xyz replied to this.

          Frodev It doesn't matter where it leads. That's the whole point of having virtual roots like res:// or user://. The OS will provide some valid writable path somewhere in the appropriate place for user data. It is not the path of Godot executable as OS doesn't even know where that is. Godot doesn't install or register itself to the OS.

          Just use user:// and don't worry about where it is. It will likely be in different places on different machines. If you need to manually check the files while developing, print the user path form within Godot using globalize_path() and look there, as I mentioned earlier.