Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Text file Output

Author
Message
RancidRat
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 2nd May 2008 14:53
I looked around the forums for help on this but could not find any help. Im still new to C++ and I am trying to understand how to export data to a text file. I want to export a list of floats and ints to a text file.
I know there was an example in the MS Visual Studio help file to do it:


This works great when I do a forms application or something like that but I cant get it to work with Dark GDK (I dont even know what files to #include)

I know that DGDK has its own functions,I get this to work fine:
dbOpenToWrite ( 1, "file.txt" );
dbWriteString ( 1,"hello");

but how would I do something like
dbWriteString ( 1,"%d", myint); ?
Do i use dbWriteLong ( 1, myint) or what?
Thank you
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 2nd May 2008 15:57


I recommend you use this though for file handles. (I have this code in a class, simply remove the JGC_FILE:: to use
as a pure function, but you MIGHT need to rename if you get a conflict. Idea being, to stop using the hardcoded Filehandles as soon as possible, because eventually you'll need a more dynamic approach.



Your issue is a linking thing with DarkGDK. Lilith told me you need to go into the project properties and change the /MTD to MD or something.. something about DarkGDK didn't supply a debug lib for us to use, and that causes the RELEASE window lib's (like IO) to not link correctly or something. So, I'll let you google this site for LINKING STDLIB IO and anything else you think of.. but it has to do with setting a flag in the linker options so that RELEASE versions of the STDLIB's compile is as RELEASE versions and not the DEBUG ones or something.

I personally don't minf the DarkGDK fileio - just to avoid linking issues... I just wish they had an "OpenForAppend" and an Append that didn't drop the Carriage Return/Line Feed, followed by null... which is fine for reading/writing strings "safely" but sometimes you might be making a file for another kind of system and nulls in text files isn't exactly standard and writing bytes to accomplish same thing is inherently slower...

Overall though I like them. If they had added simply OpenForAppend, that would help ALOT for me anyways...

Example: I have two log files.. one is a REAL LOG FILE... and appending errors makes sense. Open, append line, close... but I've had to resort to leaving file open and making it "start empty each run" and the other one, I don't mind at all being open all the time, its a message log for my GUI I'm making... I can easily track GUI "MESSAGES" and debug a little by seeing if stuff is happening out of order if a problem baffles me.

Good Luck Man!

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 2nd May 2008 18:37
Quote: "I know there was an example in the MS Visual Studio help file to do it:"


Therein is where you're making a mistake. What you were looking at as an example was strictly C#, not C++. In order to use the streams that are part of the standard libraries for C++ you need to look at the classes defined in the fstream.h file. Naturally I mean that you need to lookup "fstream tutorial" on the web. Here's one such link that my lookup found.

http://www.cplusplus.com/doc/tutorial/files.html

These would be the functions "native" to C++. In order to compile in debug mode you may need to set the project to link to non-debug libraries.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 2nd May 2008 20:45
RancidRat
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 3rd May 2008 11:31
Hey thanks so much, you guys rock, you should be in every major city...

File output is now all sorted. But I definitly want to look into using some of those native functions with Dark GDK, there is a lot of good stuff out there. I know that you cant just use #include <iostream> cuz it gives some erros and stuff.

BTW, i was wondering, if I want to allow a player to "SAVE" in the game he/she is playing, would the best way be just to write all the vars to a save file? is that how save games work?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 3rd May 2008 15:04
Short answer? Yes.. long answer... You have to make sure you can recreate the "environment" as it was when you saved in your load routine. This also depends on your game ... as to what's required. Some Games... this way is enough, others ... you also needs a "saved" version of the modified Level.. say ... the one with burnt decals, and knocked down walls, and stuff... or at least a way to load the stock level and "return" the level to its half messed up state.

However... if your game only saves in between levels... then your method is pretty much dead on IMO.
(Not knowing anything about your particular game that is)

Login to post a reply

Server time is: 2024-11-20 09:31:29
Your offset time is: 2024-11-20 09:31:29