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 / Open and Write Scores in a Textfile in DarkGDK

Author
Message
elsole
14
Years of Service
User Offline
Joined: 4th Dec 2009
Location:
Posted: 28th Feb 2010 02:39
Hi to all,

I wanted to have a scoresheets be displayed after the game ends or over. How can I open a textfile and write the scores in it and then later retrieve those scores lets say 5 top scores and display it after when the game is over.
Aldur
16
Years of Service
User Offline
Joined: 8th Oct 2007
Location: Melbourne, Australia
Posted: 28th Feb 2010 02:59
Have a read of this:
http://www.cplusplus.com/doc/tutorial/files/

Probably the way i'd go about it.

Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 28th Feb 2010 06:50
You could use a small XML file to store the scores (in a nice organized fashion), if you don't know XML, it's very basic yet useful.

And then access the file using TinyXML ->http://www.grinninglizard.com/tinyxml/

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
NightX
15
Years of Service
User Offline
Joined: 3rd Apr 2009
Location: Australia, QueensLand
Posted: 28th Feb 2010 08:35 Edited at: 28th Feb 2010 08:39
an example of Fstream. This example only writes to a file.

This is a simple example in a console application.



Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 28th Feb 2010 10:43
The most elegant way is C++ file handling of course, but for a simple purpose, you can also use Dark GDK file handling. That might be easier for you to grasp. Read the documentation about the GDK file commands.
elsole
14
Years of Service
User Offline
Joined: 4th Dec 2009
Location:
Posted: 28th Feb 2010 13:25
@Mireben

Could you give me a sample of how to use it? I read the documentation but dont know how to i'll make the code...

@NightX

I understand how your code works but what I was trying to ask is that how would i use the darkGDK commands in opening and storing data in a file. Thanks anyway and to the others who give their replies.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 28th Feb 2010 14:14
Here is a quick example which writes and reads integers.



You may also have a look at the "matedit" thread where I posted just today a code that reads strings from a file and converts those to integer values. That will help if you want to read text files. The above code writes in a format which is not human-readable.
NightX
15
Years of Service
User Offline
Joined: 3rd Apr 2009
Location: Australia, QueensLand
Posted: 28th Feb 2010 14:20 Edited at: 28th Feb 2010 14:24
kk i made a demo on how to use the DGDK file commands. READ CAREFULLY



NightX
15
Years of Service
User Offline
Joined: 3rd Apr 2009
Location: Australia, QueensLand
Posted: 28th Feb 2010 14:21 Edited at: 28th Feb 2010 14:21
lol damn you posted ur example like..6 seconds before me

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 28th Feb 2010 14:52
Just use file streams as Aldur and NightX showed, there's no point in using the GDK file functions.

elsole
14
Years of Service
User Offline
Joined: 4th Dec 2009
Location:
Posted: 1st Mar 2010 07:32
Wow thanks alot for the samples. I'll try coding now. I'll keep you posted if i got a question again.
NightX
15
Years of Service
User Offline
Joined: 3rd Apr 2009
Location: Australia, QueensLand
Posted: 1st Mar 2010 07:33
Np

Ovan35
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 3rd Mar 2010 04:17 Edited at: 3rd Mar 2010 04:21
This topic is really close to one I've been working on for a while.I was hoping that you guys could help me out.I'm trying to get my stats taken from my characters txt files and have the stats place onscreen.Which sounds pretty similar to what's going on.I thought I had it with my last attempt but there were far too many errors when I finally compiled it.



and the Anko.txt file


Largely it's acting like it's totally wrong to use =,==,!=, when dealing with char data.That's basically the kind of errors I get when I compile it.But if not that then what?Am I totally off base or what?

It was such a small seed... I needed to find out what was growing inside. And there was only one way to find out. So I decided to raise it.

Marsh0
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 3rd Mar 2010 07:07 Edited at: 3rd Mar 2010 07:08
Ok, you were missing a bracket in your while statement, you had one char * and the rest were normal chars and you cant compare the two which is why your == wasnt working. Also you were using a array but you never declared the initial number of the array.

Here is the fixed code below.


Never actually tested it but your errors are gone.

Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
Ovan35
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 3rd Mar 2010 09:14
Thank you for the assist I will try it out right away and see how it works.I do have a question I understand the ASCII signs < and > as the code for < and > but why are they used instead of just the actual symbol?

And although I did have char *MyString[] as a pointer.I couldn't quite figure out why it was that way?Pointers point to the address where data is stored not the value itself right?

It was such a small seed... I needed to find out what was growing inside. And there was only one way to find out. So I decided to raise it.

Ovan35
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 3rd Mar 2010 09:39
I'm afraid it didn't work.I got Linker errors.I tried changing the configuration properties but no luck there.I'm going to start from scratch and try again.

It was such a small seed... I needed to find out what was growing inside. And there was only one way to find out. So I decided to raise it.

Marsh0
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 3rd Mar 2010 17:31 Edited at: 3rd Mar 2010 17:35
Goto project then goto properties goto c/c++ goto code Generation and change the runtime library to Multi Threaded and not multi threaded debug.

Also here is a working and tested program to do exactly what you want. You may need to convert your strings to ints later in use of your program but this will read it and display it.

Main Program


Here is your Anko.txt




Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
Ovan35
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 4th Mar 2010 02:38
Thank you so very much.It seems I was way off.Your code didn't look like mine in the slightest.I know this may be a huge question and you might not have an answer for it but how do you figure this stuff out?I can copy and modify code that I see but when it comes to making anything original I'm screwed.

I've been going to cplusplus.com a good bit.A bit of a dry read but I try to learn between eyelid closures.

It was such a small seed... I needed to find out what was growing inside. And there was only one way to find out. So I decided to raise it.

Marsh0
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 4th Mar 2010 06:48 Edited at: 4th Mar 2010 06:56
I just screw around and eventually you get it. As for the file reading i googled it. I ask questions on forums when i get stuck and i search it all up online. You werent necessarily doing it wrong, just differently.

As for reading the files i just found how here:

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

Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
helpfull programmer
15
Years of Service
User Offline
Joined: 30th Jul 2009
Location:
Posted: 27th Mar 2010 15:59
The dark GDK file functions are very useful when dealing with Multi-sync as the functions from <fstream> clash badly. Just though I would point that out
Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 27th Mar 2010 22:40
yeah but the gdk file functions are prone to memory leaks!

hi
haliop
User Banned
Posted: 28th Mar 2010 11:24
as i understand everything in DarkGDK leaks..
i guess it has a plumming problem.


someone call Smario.!!!

Login to post a reply

Server time is: 2024-10-02 03:32:25
Your offset time is: 2024-10-02 03:32:25