CRE8OR - game maker for anim8or

 


FILE IO


You'll need Cre8or Version 0.10a in order to run this correctly. A lot of times you may need to read and write from files. Thus tutorial will show you th functions of reading and writing.

For documentation on using the Cre8or scripting, read the Squirrel Language Reference

When you write to a file, you'll need to use the opne a file, like so:

file_ handle = fopen(file_name, open_type)

Where file_name is the name of the file in quotes. And open_type is how the file is opened, use "rb" for Read Binary and "wr" for Write Binary:

local file_handle = fopen("game.dat", "wb");

For writing objects to a file you can use the following:

fwrite_int(integer, file_handle)

fwrite_flt(float, file_handle)

fwrite_bool(boolean, file_handle)

fwrite_str(string, file_handle)

//write line
fwrite_ln(string, file_handle)

For reading from a file

integer = fread_int(file_handle)

float = fread_flt(file_handle)

bool = fread_bool(file_handle)

string = fread_ln(file_handle)

Example:

//write variables
fwrite_int(health, file_handle)
fwrite_int(score, file_handle)
fwrite_ln(name, file_handle)

//read_variables
health = fread_int(file_handle)
score = fread_int(file_handle)
name = fread_ln(file_handle)

Always reme,ber to close the file after reading or writing:

fclose(file_handle);

To see if a file exist use:

fexists(file_name);

To create a directory use:

mkdir(directory);

That's it for now on file handling


Tutorials Page




Copyrights (C) 2007 Keith Tabert
Thanks to R. Steven Glanville for Anim8or, Robin