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 / Highscore function!

Author
Message
JIMAC
12
Years of Service
User Offline
Joined: 25th Nov 2011
Location: Scotland
Posted: 15th Jul 2012 14:05
Ok time to be a complete noob!

I have spent days trying to use filesaves for my game, in which i get the users name from user input, then record the score from their game, then sort the table so the high scores are in descending order.

thegdk functions seem to always bring a overrun issue, so as suggested i went back to core C++ using fstream and all that file system stuff, but that won't work, all this really puts me off gdk, can someone anyone make a tutorial from start to finish of a way to save to file sort it and read it back PLEASE!

Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 15th Jul 2012 14:51
Here is some example code:


The fastest code is the code never written.
JIMAC
12
Years of Service
User Offline
Joined: 25th Nov 2011
Location: Scotland
Posted: 15th Jul 2012 15:33
Thanks Hawk,

some questions

what header file do you include for this ie #include<fstream> etc.?

struct SCORE - i dont get the struct is this the a variable type like int, char etc..?

other than that i get it, but using it has me stumped!

Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 15th Jul 2012 16:00
stdio.h

A struct is a type cast. It makes SCORE into a variable type. You can also use "class" just like struct. Google them for better info. The big difference is that classes are intrinsically "private" and structs are "public". Functionally, they are identical. You can create functions inside your struct/class so you can keep your program neat an tidy. Here's an example from what I'm doing right now:

Notice "LIGHTSOURCE(){};" at the top? That is "what it will do when its initialized" just like "SCORE(){memcpy(Name,'\0',20);Score=-1;}" from the example I gave you. This is known as the "constructor". Mine has "~LIGHTLIST();" which is known as the "destructor". I bet you can quess what it does.... Constructors/destructors are called for each itteration of that class/struct so in your case the constructor is called 20 times when the pointer "HighScore" is created ( HighScore[20]; ) .

The fastest code is the code never written.
JIMAC
12
Years of Service
User Offline
Joined: 25th Nov 2011
Location: Scotland
Posted: 15th Jul 2012 22:40
Ok got it somewhat, why the hell do the dgdk functions not work properly , i have no idea about class's and such yet guess i got some reading to do thanks anyway Hawk your a good guy on the forum's.

JIMAC
12
Years of Service
User Offline
Joined: 25th Nov 2011
Location: Scotland
Posted: 15th Jul 2012 23:24
I got it to work this way!



Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 15th Jul 2012 23:26
Most of GDK1.0 works just fine. GDK2.0 is still in testing and has a lot of problems. Some have been called "features", but some of those I don't like.

Are you using 1.0 or 2.0?

The fastest code is the code never written.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 15th Jul 2012 23:33
Quote: "I got it to work this way!"
Good. I'm a little confused that you aren't using a struct or class.

The fastest code is the code never written.
JIMAC
12
Years of Service
User Offline
Joined: 25th Nov 2011
Location: Scotland
Posted: 15th Jul 2012 23:34
1.0 i have never upgraded, could cause me problems but still getting used to it all, again though thanks for taking the time to try and help me i do appreciate it!.

Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 15th Jul 2012 23:35
No problem.

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-11-19 00:44:49
Your offset time is: 2024-11-19 00:44:49