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$()
function download(url$, filename$, maxSize, timeout)


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$()

Return path to the user's home directory.

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


function download(url$, filename$, maxSize, timeout)

Download a file specified by url. No matter what url says, the destination filename, on disc, will be filename. maxSize is the maximum size of the file to be downloaded. timeout is unused, set it to 0.

You can use this command not only to download files, but also to fetch the output of, for example, php scripts (in that case, the downloaded file will be a text file).


[ Back ]