I have an app with a data.txt file in the root folder (comes pre-loaded on a mobile with the app). I want to read and write to this file. I can read from the file using res:// but I cannot write to it since I have to use 'user://' prefix, which points to a different location I believe.
Here's my code fragment:
var file_read = File.new()
if(file_read.open("res://data.txt", File.READ) != 0):
$lbl_file_data.text = "error opening file"
$lbl_file_data.text = file_read.get_as_text()
var text = $TextEdit.text
var file_write = File.new()
$lbl_file_data.text = "no file to write to"
elif(file_write.open("user://data.txt", File.WRITE) != 0):
$lbl_file_data.text = "error writing to file"
How can I write to the same file that I read data from? Do I have to create a file programatically on app startup?
ps...the automatic 'code sample' button in writing this question may create erroneous code formatting