Files

[ Back ]

NaaLaa supports both text and binary files.

Sub routines

procedure create file file_id, filename$[, binary]
procedure write file file_id[, expr [, expr ...]]
procedure wln file file_id[, expr [, expr ...]]
procedure write8 file_id, data
procedure write16 file_id, data
procedure write32 file_id, data
procedure writef file_id, data#
procedure writes file_id, data$
procedure open file file_id, filename$[, binary]
function read(file_id)
function read#(file_id)
function read$(file_id)
function read8(file_id)
function read16(file_id)
function read32(file_id)
function readf#(file_id)
function reads$(file_id)
function file(file_id)
function eof(file_id)
function exists(filename$)
function openfile$(extension$)
function savefile$(extension$)
procedure free file file_id
function datafolder$(directory$)


procedure create file file_id, filename$[, binary]

Create file file_id with the name filename for writing. If a file with the same name already exists, it is replaced by the new file. If binary is set to false (default), the file will become a text file, else it will become a binary file.


procedure write file file_id[, expr [, expr ...]]

Write a number of arbitrary expressions to file file_id. This only works on text files.


procedure wln file file_id[, expr [, expr ...]]

Write a number of arbitrary expressions to file file_id and add a line break. This only works on text files.


procedure write8 file_id, data

Write an 8 bit (byte) value, data, to file file_id. This only works on binary files.


procedure write16 file_id, data

Write a 16 bit (short) value, data, to file file_id. This only works on binary files.


procedure write32 file_id, data

Write a 32 bit (long) value, data, to file file_id. This only works on binary files.


procedure writef file_id, data#

Write a float value, data, to file file_id. This only works on binary files.


procedure writes file_id, data$

Write a string, data, to file file_id. In the file, the string is a character (byte) sequence terminated by null (a byte with the value 0). This only works on binary files.


procedure open file file_id, filename$[, binary]

Open file file_id with the name filename for reading. If binary is set to false (default), the file will be treated as a text file, else it is assumed to be a binary file.


function read(file_id)

Read and return an integer value from file file_id. This only works on text files.


function read#(file_id)

Read and return a float value from file file_id. This only works on text files.


function read$(file_id)

Read and return a string from file file_id. This only works on text files.


function read8(file_id)

Read and return an 8 bit (byte) value from file file_id. This only works on binary files.


function read16(file_id)

Read and return a 16 bit (short) value from file file_id. This only works on binary files.


function read32(file_id)

Read and return a 32 bit (long) value from file file_id. This only works on binary files.


function readf#(file_id)

Read and return a float value from file file_id. This only works on binary files.


function reads$(file_id)

Read and return a string from file file_id. This only works on binary files.


function file(file_id)

Return true if file file_id has been opened/created.


function eof(file_id)

Return true if end of file file_idhas been reached.


function exists(filename$)

Return true if a file with the name filename exists.


function openfile$(extension$)

Show a standard windows dialog for opening a file. The selected filename is returned. If extension is not an empty string, only files with the specified extension (ex. "txt") will be visible.


function savefile$(extension$)

Show a standard windows dialog for saving a file. The selected filename is returned. If extension is not an empty string, only files with the specified extension (ex. "bmp") will be visible.


procedure free file file_id

Close file file_id. All files are automatically closed when the program exits.


function datafolder$(directory$)

Return path to the application data folder of all users. If directory is not an empty string, a folder with that name will be created (if not present) and added to the return value.

If you want to save "hidden" data, like a game save file, on a user's computer, it is strongly recommended that you use this function to get a valid path. Ex:

filename$ = datafolder$("my_game") + "savefile.bin"
create file 0, filename$
...


[ Back ]