Questions about WriteString to File (SOLVED)

Started by TheMagician, Sat 12/11/2005 16:46:05

Previous topic - Next topic

TheMagician

Hi everybody!

First of all, I think it is not possible to change the description of a savegame slot after the safegame has been created. Right?

So I'm playing with writing to files for the first time.
Here is question one:

If I write a string into a file using this code:

String buffer = "TestDescription"; 
File *output = File.Open("SaveDescription.dat", eFileWrite);
output.WriteString("%s", buffer);

I get the error "Invalid number of parameters in WriteString". So, how can I write a buffer into the file?

And one more question: if I write multiple strings into a file (always using the "WriteString" function) how do I know which one I get if I later use the "ReadStringBack" function?

Many thanks in advance!
Stefan

Rui 'Trovatore' Pires

1st - CHange the description of a savegame? Sort of - if you overwrite the slot with a new saved game with a new description... but I think that's all you can do.

2nd - I don't have access to the manual right now, but check out whatever has replaced the StrFormat() function and use it to create the string you need for "output.WriteString".

3 - From what I understand, it goes like this: open a file and call five WrtiteStrings and 5 will be created -. let's call them 1 to 5. Then close it and call ReadStrings 5 times - the five will be called, in the same order. Andf if you wanted to, say, read the fourth string, you'd call ReadString 4 times, always overwriting the previous one. I THINK this is how it works... bit of a hassle IMHO but not a major one, and it works.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

TheMagician

Thanks for your answer, Rui!

The Manual says that StrFormat() was replaced by

static String.Format(string fmt, ...)

I tried to implement it this way:

String buffer = "test";
File *output = File.Open("SaveDescription.dat", eFileWrite);
output.WriteString( String.Format("%s",buffer) );
output.Close;

However, I get an error in the last line of the above script:       Expected '('

Any ideas?

Ashen

I know what you're thinking ... Don't think that.

TheMagician


:-X ... ups  ::)

Well, now it works.
Thanks for your help!


Pumaman

Also, there's no need to do this:

output.WriteString( String.Format("%s",buffer) );

since you can just do this:

output.WriteString(buffer);

And yes, as Rui says, if you use multiple WriteStrings, then ReadString will read them back one by one in the same order as you wrote them.

SMF spam blocked by CleanTalk