Creating a .txt file

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

Creating a .txt file

Postby FERdeBOER » Sun Jul 18, 2010 3:33 am

I always doubt about where to make my questions... :?

This time is this: Can I make my game to create a .txt file? (of course with the things I want to be writen on it).
Where that .txt file would be created? Could the player select the destination folder?

Thank you very much for your time.
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 Fuzzy » Sun Jul 18, 2010 4:37 am

FERdeBOER wrote:This time is this: Can I make my game to create a .txt file? (of course with the things I want to be writen on it).

Yes.

Where that .txt file would be created?

In the game folder.

Could the player select the destination folder?

No. At least not in the way you are imagining.

Thank you very much for your time.

Welcome.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Creating a .txt file

Postby FERdeBOER » Sun Jul 18, 2010 10:42 am

Fuzzy wrote:
FERdeBOER wrote:This time is this: Can I make my game to create a .txt file? (of course with the things I want to be writen on it).

Yes.


Oh, :)

Could you please be more specific about how can I do it?

Thank you again for your help and your fast answer.
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 » Sun Jul 18, 2010 10:55 am

Code: Select all
FILE *f=fopen("yourfile.txt","w");
fprintf(f,"Hello world");
fclose(f);
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 » Sun Jul 18, 2010 11:43 am

Thank You very very much!

It works perfectly!!

Should I put "solved" on the topic subject or something?
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 » Sun Jul 18, 2010 1:14 pm

You're welcome :D
If you keep it maybe someone will give more reply with more code variation :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 » Sun Jul 18, 2010 6:36 pm

Now you mention it... any tip about how to insert multilines text? I need to copy and paste from another text file which is already in multiline.
I've found 3 solutions: adding " at the start and end on each line, or \ at the end of a line...
there's also the possibility of making a unique line with \n on each line end... but is all three are a LOT of job, so if it's a way of just paste the text as it is...

Thank you again, and again...
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 FERdeBOER » Mon Jul 19, 2010 7:01 pm

I have a problem inserting my multiline code.

I'll try to make a short brief about what I want:
I'm trying to make random missions to a game called Dangerous Waters (DW to abreviate), a naval warfare simulation. It's a great game but lacks of a dynamic campaign and a good random mission generator.
I has, however, a very good mission editor and the missions are in simple text, so it can be read by notepad.
So what I'm trying to do is making a good random mission generator by creating a bunch of different situations in the DW editor, then copying all of them to my game-editor program and it will give out a mission generated choosing between the ones I selected and randomizing the weather conditions. (That's why I asked for creating a .txt file and, even better, game-editor can create directly a .mu file, the mission ones on DW). :)

My first problem is, as I said above, the multiline. Porting a very simple mission to game-editor is already long... porting a bit more complex mission will be terrible :?
So, please, any tip about how to do this would be very apreciated.

My second problem is when trying to randomize weather.
This is my code (well, is more Bee-Ant's):
Code: Select all
FILE *f=fopen("00base.mu","w");
fprintf(f,"VERSION 3"
"OWNALLIANCE 0"
"DIFFICULTY 1"
"TOTALNUMSIDES 1"
"NUMDRIVEABLES 1"
"MONTH 1"
"WORLDGRID 2"
"LATLONG 54.071823 -11.025635"
";"
"SEASTATE %i\n",seastate
"MDR 0 0 0"
"BOTTOMTYPE %i\n",bottomtype
"TIMEOFDAY %i\n",timeofday
"WEATHER %i\n",weather
"CLOUDHEIGHT %i\n",clouds
"SSP %i\n",ssp
""
""
"ENTITY 2342 SUBENTITY"
"HULLID 1"
"ALLIANCE 1"
"POS 305928.125000 597045.187500 -70"
"POINTS 750"
"COURSE 0"
"SPEED 5"
"PROB 100"
"DRIVEABLE 1"
"UNIQUENAME "SSN""
"COMMSINTERVAL 0.000000"
"TACTIC RANDOMBOX"
"BOX 266453.875000 638493.187500 345402.343750 555597.250000"
"AIRLOADOUT 244"
"AIRCRAFT 1722 1 Alert5 0 : Alert15 1 : 0 Alert30 0 : "
"END");
fclose(f);


This is a mission with just one submarine (the player). No other objects, no missions... figure out how hard would be to add quotes to all lines on a normal mission... :|

My problem is that, when I press ok I got this error: "Error line 13: expected )"
line 13 is the bottomtype one.

the seastate, bottomtype, weather... variables are been defined before and are like:
Code: Select all
seastate=rand(5);
bottomtype=rand(3);

and so on...

I switched some lines and the problem is after the first random event so in not line 13 the problem, but where the second random event is).

What can it be?

I hope to have been clear enough, I'm not English.
Thank you very much.

EDIT:
If I change the quotes for \
Code: Select all
FILE *f=fopen("00base.mu","w");
fprintf(f,"VERSION 3" \
OWNALLIANCE 0\
DIFFICULTY 1\
TOTALNUMSIDES 1\
NUMDRIVEABLES 1\
MONTH 1\
WORLDGRID 2\
LATLONG 54.071823 -11.025635\
;"\
SEASTATE %i\n,seastate \
MDR 0 0 0\
BOTTOMTYPE %i\n,bottomtype \
TIMEOFDAY %i\n,timeofday \
WEATHER %i\n,weather \
CLOUDHEIGHT %i\n,clouds \
SSP %i\n,ssp \
\
\
ENTITY 2342 SUBENTITY \
HULLID 1 \
ALLIANCE 1 \
POS 305928.125000 597045.187500 -70 \
POINTS 750 \
COURSE 0 \
SPEED 5\
PROB 100\
DRIVEABLE 1\
UNIQUENAME "SSN" \
COMMSINTERVAL 0.000000\
TACTIC RANDOMBOX\
BOX 266453.875000 638493.187500 345402.343750 555597.250000\
AIRLOADOUT 244\
AIRCRAFT 1722 1 Alert5 0 : Alert15 1 : 0 Alert30 0 : \
END");
fclose(f);


I gives me no more the first error, but
Error line 35: Expected )
Error line 35: Expected ;

But line 35 already has ); :?

Also, the line
UNIQUENAME "SSN"
, has this format on the mission files, each platform has its name and comes quoted, can this be a problem?
I'm pretty lost, as you can see..
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 Game A Gogo » Mon Jul 19, 2010 10:38 pm

to have multiline strings, simply use the escape sequence \n
Code: Select all
fprintf(f,"Hello,\n\tworld!");

here \t is the escape sequence for a tab space
So it'd appear as:
Code: Select all
Hello,
    world!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Creating a .txt file

Postby FERdeBOER » Tue Jul 20, 2010 12:54 am

Game A Gogo wrote:to have multiline strings, simply use the escape sequence \n


I've already tried this, is as long to do as quoting or putting \ ... and less clear... however, I've just tried it, without "my" random options and it works, but if I put the first random variable (seastate), the final text file ends at that point, not writing what follows...

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\n",seastate,"\nMDR 0 0 0\nBOTTOMTYPE 1\nTIMEOFDAY 21\nWEATHER 0\nCLOUDHEIGHT 30\nSSP 2\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");
fclose(f);


How can I make the program to resume writing the text?
I know is a very silly question, but I can't find a solution (it's one hour I'm searching on internet). :roll:

Thanks again for your patience.

EDIT:
I forgot to say that the text file writes correctly the random seastate, it stops just after it.
to make it more clear, I paste the point where I think it's the problem:
Code: Select all
\nSEASTATE %i\n",seastate,"\nMDR 0 0 0\n
Last edited by FERdeBOER on Tue Jul 20, 2010 1:01 am, edited 1 time in total.
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 Hblade » Tue Jul 20, 2010 1:00 am

Its over 256 characters, which could be the reason probably
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Creating a .txt file

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

Hblade wrote:Its over 256 characters, which could be the reason probably


You talk about the text? But if I don't put the random variables the entire text is written...
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 Hblade » Tue Jul 20, 2010 1:15 am

Strange... Usually it will give you an error if you use any print or sprint command, and have over the max limit character of 256.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Creating a .txt file

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

Hblade wrote:Strange... Usually it will give you an error if you use any print or sprint command, and have over the max limit character of 256.


Well, I had no problem at all... maybe because is an external text, not displayed in the game? :?:

However, how can I connect the lines after the seastate value? I've just made test with a short line and allways stops writing after the variable and I would need to continue writing.
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 Hblade » Tue Jul 20, 2010 1:27 am

thats a good question, sorry but I'm not too good with FILE * stuff :P
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Next

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron