Creating a .txt file

You must understand the Game Editor concepts, before post here.

Re: Creating a .txt file

Postby FERdeBOER » Tue Jul 20, 2010 1:45 am

I DID IT!! :mrgreen:

Code: Select all
FILE *f=fopen("00base.mu","w");
fprintf(f,"VERSION 3\nOWNALLIANCE 0\nDIFFICULTY 1\nTOTALNUMSIDES 1\nNUMDRIVEABLES 1\nMONTH 1\nWORLDGRID 2\nLATLONG 54.071823 -11.025635\n;\nSEASTATE %i\nMDR 0 0 0\nBOTTOMTYPE %i\nTIMEOFDAY %i\nWEATHER %i\nCLOUDHEIGHT %i\nSSP %i\n\n\nENTITY 2342 SUBENTITY\nHULLID 1\nALLIANCE 1\nPOS 554859.937500 559978.937500 -70\nPOINTS 750\nCOURSE 0\nSPEED 5\nPROB 100\nDRIVEABLE 1\nUNIQUENAME ""SSN"" \nCOMMSINTERVAL 0.000000\nTACTIC RANDOMBOX\nBOX 515385.812500 601426.937500 594334.187500 518531.031250\nAIRLOADOUT 244\nAIRCRAFT 1722 1 Alert5 0 : Alert15 1 : 0 Alert30 0 : \nEND\n", seastate, bottomtype, timeofday, weather, clouds, ssp);
fclose(f);


Making it more clear:
Code: Select all
FILE *f=fopen("00base.mu","w");
fprintf(f,"\nBOTTOMTYPE %i\nTIMEOFDAY %i", bottomtype, timeofday);
fclose(f);

So the %i places the final variables in the order written.

And now all the text appears on the text file :D

Don't relax, surely I will come back with more questions... :twisted:

Thank You all for your help!
FERdeBOER
 
Posts: 36
Joined: Fri Mar 12, 2010 8:03 pm
Location: Good question...
Score: 0 Give a positive score

Re: Creating a .txt file

Postby Bee-Ant » Tue Jul 20, 2010 1:55 am

Hmmm...I thought you were asking on how to keep writing on the text file without worrying on 256 character limit...
But if yes, use "a+" flag on the FILE declaration :
Code: Select all
FILE *f=fopen("yourfile.txt',"a+");

a+ will add the text from the last line, not rewrite the text from beginning.
Hope it helps :D
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Creating a .txt file

Postby FERdeBOER » Tue Jul 20, 2010 2:50 am

Bee-Ant wrote:Hmmm...I thought you were asking on how to keep writing on the text file without worrying on 256 character limit...
But if yes, use "a+" flag on the FILE declaration :

No, moreover, I didn't know that there was such a limit since Hblade mentioned it :roll:

Bee-Ant wrote:
Code: Select all
FILE *f=fopen("yourfile.txt',"a+");

a+ will add the text from the last line, not rewrite the text from beginning.
Hope it helps :D

Great! It's very useful for what I want to do. With this I don't need to copy all the lines, but write only the ones I want to be random.

Oh, may I ask you one more thing?
With the a+ method the problem I see is that it only works once, because repeating lines makes DW crash. So I think the solution would be copying the original file (lets call it originalmission.txt), lets say to randommission.txt and then add the modified code with a+.
Can it be done? Am I asking too much? :oops:
FERdeBOER
 
Posts: 36
Joined: Fri Mar 12, 2010 8:03 pm
Location: Good question...
Score: 0 Give a positive score

Previous

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron