FileReadString Problem
Displaying 1-13 of 13 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Interference22

Using FileWriteString and FileReadString to create save files is presenting me with a problem. Saving integers as strings and then val()ing them back to integers is fine, but my strings are getting junk characters added to the end of them.

I tried to load the current map the player was in from my save file. The string should contain the word "test," which then has a "m-" stuffed at its star and a ".map" at its end in the mapload function to load "m-test.map." Instead, it crashes with this error:



Is it reading the ASCII characters that mark the end of a string as well as the string? My VC doesn't seem out of the ordinary, its just a straight set of FileWriteString()s in the save game function and a load of FileReadString()s in the load function. The mode for FileOpen() is set correctly in both cases.

Posted on 2004-04-23 22:46:58

vecna

quite likely. the file i/o functions havent been tested extensively since the first time they were written over a year ago for the original version of v3. I'll look into it this weekend.

Posted on 2004-04-24 01:26:00

rpgking

There definitely is a problem with these 2 functions. I forgot to report this earlier, but I encountered the same thing when working on Balloon Ninjas, and had to make my own custom functions to do these...

Posted on 2004-04-24 05:45:07

vecna

I am trying to debug this now, but am unable to duplicate any problem. Here's the code I'm using:

void autoexec()
{
int f = FileOpen("caca.txt", FILE_WRITE);
FileWriteString(f, "This is a test of your mom!");
FileClose(f);

f = FileOpen("caca.txt", FILE_READ);
string s = FileReadString(f);
FileClose(f);
Exit(s);
}


It works fine.
Can anyone give me code that doesnt work?

Posted on 2004-04-26 23:47:04

rpgking


void autoexec()
{
int f = FileOpen("caca.txt", FILE_WRITE);
string s;

FileWriteString(f, "rpgking");
FileWriteString(f, "100000");
FileWriteString(f, "vecna");
FileWriteString(f, "1111111111");

FileClose(f);

f = FileOpen("caca.txt", FILE_READ);

s = FileReadString(f); log(s);
s = FileReadString(f); log(s);
s = FileReadString(f); log(s);
s = FileReadString(f); log(s);

FileClose(f);

Exit("");
}


These are my logfile results:
---------------------------------
rpgking
100000g
vecna0g
1111111111‹

FileWriteString is supposed to write a string to a binary file right? And FileReadString reads the next string from that binary file? If so, then something's not working right with the functions. If not, there's something I'm missing here :P

Posted on 2004-04-27 03:48:34 (last edited on 2004-04-27 04:01:44)

mcgrue

Zany. I get:

rpgking
100000g
vecna0g
1111111111a1"

why the difference, I wonder...

Posted on 2004-04-27 06:45:04

Rysen

What's really weird is that if I do vec's version and open caca.txt, everything looks fine but when I do rpgking's, I get Japanese kanji. o_O

In the log file though, I get the same result as grue.

Posted on 2004-04-27 11:05:50

el_desconocido

I think the internal string buffer is not being cleared for some reason.The 0g after vecna is left from lines 1 and 2. Using two different strings also lets artifacts through. Caca.txt does have binary seperators, don't know if that's the intention.

Or maybe that's chance because:
This:
    FileWriteString(f, "-rpgkingisagog");

FileWriteString(f, "1");


logged this:
-rpgkingisagog?
1`[ð]H

Posted on 2004-04-27 15:11:44

rpgking

Grue's log file is probably correct. I may have copied the last few weird characters wrong.

Posted on 2004-04-27 16:46:19

vecna

Yeah, caca.txt was a misleading name. It's not really a text file, there are binary values output by FileWriteString().

Should be fixed this weekend.

Posted on 2004-04-27 18:06:55

mcgrue

Just in case there was any confusion, I was reporting my v3.log's contents after the:

s = FileReadString(f); log(s);
s = FileReadString(f); log(s);
s = FileReadString(f); log(s);
s = FileReadString(f); log(s);

section of the above code.

Posted on 2004-04-27 21:08:27

el_desconocido

I knew what you meant but was confused myself.
Entire Autoexec()
void Autoexec()

{
int f = FileOpen("caca.txt", FILE_WRITE);
string s;
string t;
FileWriteString(f, "-rpgkingisagog");
FileWriteString(f, "1");
FileWriteString(f, "vecna");
FileWriteString(f, "1111111111");

FileClose(f);

f = FileOpen("caca.txt", FILE_READ);

s = FileReadString(f); log(s);
t = FileReadString(f); log(t);

FileClose(f);



Map("Xtreme.map");
}

Entire v3.log:
VC System Compilation stats:
34 ints (285 expanded), 3 strings (51 expanded), 19 functions, 803 total lines

compiled Xtreme.map, (551 lines) number of funcs is 56
-rpgkingisagog?
1`[ð]H

(eof)

And caca.txt looks correct.

El

Posted on 2004-04-28 03:06:07

vecna

fixed in the next build - you can get a quickfix exe here

Posted on 2004-04-30 03:00:41


Displaying 1-13 of 13 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.