-
Notifications
You must be signed in to change notification settings - Fork 0
File Reading & Writing
Nova provides simple and straightforward commands for interacting with the file system. Whether you want to save data or read it back later, Nova makes it easy to manage.
Use the write_file function to write text to a file. If the file does not exist, Nova will create it automatically. If it already exists, the content will be overwritten.
- Syntax:
write_file("filename.txt", "text to write goes here")
- Example:
write_file("fruits.txt" "apple,banana,cherry")
This example creates or overwrites a file named fruits.txt with the text apple,banana,cherry.
To write to memory, it follows the same syntax, but instead of write_file() it becomes mem_write()
To read the contents of a file, use the read_file function. The content is then returned as a string, which you can store in a variable for further use.
- Syntax:
have variableName = read_file("filename.txt")
- Example:
have fileContents = read_file("fruits.txt"0
put("File contents: " + fileContents)
To read what you wrote memory, it follows the same syntax, but instead of read_file() it becomes mem_read()
File I/O (input / output, aka. writing / reading) is especially useful when combined with event handlers, such as button clicks, to log actions or save user data.
- Example:
button("Log Click", 20, 110) {
clicked() {
write_file("click_log.txt", "Button clicked at " + current_time())
}
}
Join our discord server for any support or questions that you need answered!
Link: