Skip to reading
PCA Script Programming

read_text_file()

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
On this page
Code example
read_text_file(path, fallback = "")

Read the complete contents of a text file.

Returns: Text; fallback if the file is missing or cannot be opened.

Code example
read_text_file("user://notes.txt", "")

write_text_file()#

Code example
write_text_file(path, text)

Write the complete text, creating parent directories where needed.

Returns: Boolean success.

Code example
write_text_file("user://notes.txt", "Visited the archive.\n")

Only user:// writes are accepted. Existing content is overwritten, not appended.

read_json_file()#

Code example
read_json_file(path, fallback = null)

Read a text file and parse its JSON.

Returns: Parsed data or fallback.

Code example
read_json_file("user://preferences.json", {"music": 0.7})

In this helper, JSON null also selects the fallback. Use from_json(read_text_file(...)) when valid null must be distinguished from failure.

write_json_file()#

Code example
write_json_file(path, value, indent = "\t")

Serialize JSON and overwrite a user-data file.

Returns: Boolean success.

Code example
write_json_file("user://preferences.json", {"music": 0.5}, "  ")

This is a custom data file, not a replacement for a full game save.

Page 74 of 357Permalink
Go to page