Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: TheMagician on Sat 12/11/2005 16:46:05

Title: Questions about WriteString to File (SOLVED)
Post by: TheMagician on Sat 12/11/2005 16:46:05
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
Title: Re: Questions about WriteString to File
Post by: Rui 'Trovatore' Pires on Sat 12/11/2005 17:36:11
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.
Title: Re: Questions about WriteString to File
Post by: TheMagician on Sat 12/11/2005 18:09:58
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?
Title: Re: Questions about WriteString to File
Post by: Ashen on Sat 12/11/2005 18:20:05
output.Close();, perhaps?
Title: Re: Questions about WriteString to File
Post by: TheMagician on Sat 12/11/2005 19:55:21

:-X ... ups  ::)

Well, now it works.
Thanks for your help!

Title: Re: Questions about WriteString to File
Post by: Pumaman on Sun 13/11/2005 11:48:32
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.