0 votes

Hi, so what I want to do is create a new JSON file out of some content that the user puts in themselves. I would like to save this to a new JSON file when this happens. Is there a way of creating a new file, or must it always save to a preexisting file?

in Engine by (290 points)

1 Answer

+1 vote

When you save a file in Godot using the WRITE flag, if the file doesn't exist, it will be created. If it already exist, it will be replaced: http://docs.godotengine.org/en/stable/classes/class_file.html#numeric-constants

var file = File.new()
file.open("user://save.json", File.WRITE)
file.store_string(json_text)
file.close()
by (27,952 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.