I got an error when I try to use my own save-mechanism. I'm using the build in file functions to save a pattern of dots (purely for testing purposes).
I'm using this code for saving:
{
var fname, file, nn;
fname = get_save_filename("files (*.txt)|*.txt","");
if (fname == "") exit;
file = file_text_open_write(fname); /* opens a file */
nn = instance_number(obj_dot); /* number of dots */
file_text_write_real(file,nn); /* write it to the file */
with (obj_dot)
{
file_text_write_real(file,x); /* writes x-position of dot */
file_text_write_real(file,y); /* writes y-position of dot */
}
file_text_close(file); /* closes file */
}and I use this code for loading a file:{
var fname, file, nn, xx, yy;
fname = get_open_filename("files (*.txt)|*.txt","");
if ((fname == "") || !file_exists(fname)) exit; /* if the name is empty or doesn't exist, game maker will crash. Hence this error check */
with (obj_dot) instance_destroy(); /* remove old dots */
file = file_text_open_read(fname);
nn = file_text_read_real(file); /* reads how many dots are saved */
for (i=0; i<nn; i+=1)
{
/* create new dots */
xx = file_text_read_real(file);
yy = file_text_read_real(file);
instance_create(xx,yy,obj_dot);
}
file_text_close(file); /* closes file */
}but when I use the loadscript, it gives an error saying: error reading real. when I check the file, all positions are there, so my question is: why do I get this error?
Edited by Plastic, 24 February 2012 - 06:32 PM.











