Author Topic: Questions about WriteString to File (SOLVED)  (Read 419 times)  Share 

TheMagician

    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Questions about WriteString to File (SOLVED)
« on: 12 Nov 2005, 16:46 »
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
« Last Edit: 14 Nov 2005, 18:37 by strazer »

Rui 'Trovatore' Pires

  • Lunge da lei per me non v'ha diletto!
    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: Questions about WriteString to File
« Reply #1 on: 12 Nov 2005, 17:36 »
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

    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: Questions about WriteString to File
« Reply #2 on: 12 Nov 2005, 18:09 »
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

Re: Questions about WriteString to File
« Reply #3 on: 12 Nov 2005, 18:20 »
output.Close();, perhaps?
I know what you're thinking ... Don't think that.

TheMagician

    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: Questions about WriteString to File
« Reply #4 on: 12 Nov 2005, 19:55 »

 :-X ... ups  ::)

Well, now it works.
Thanks for your help!


Pumaman

  • Creator of AGS
  • Administrator
  • Mittens TRAITOR
  • I sense danger.
    • Lifetime Achievement Award Winner
    •  
Re: Questions about WriteString to File
« Reply #5 on: 13 Nov 2005, 11:48 »
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.