Page 1 of 1

Lesson 19 - save file not being created

Posted: March 30th, 2015, 9:48 am
by Bumble
firstly thanks so much to Chilli for creating a programming tutorial in plain english and for not going the "hello world!" approach too. it's nice to jump straight into putpixel calls. appreciated :)
--------------------------------------------------------------------------------------------------------

RE: PooFace Ex Alpha - file not being created

Using Visual Studio 2013 ( i think ) whatever the latest version is at this time

assuming this forum is still active, hopefully i can get some much needed advice

checked code many times. the game works and builds fine. no errors other than the warnings for using printf etc and not the safe versions.

can someone please help. i can't move on till i get this sorted and i really want to move on to the last few lessons and then the intermediate tutorials.

i had the same issue with the earlier part of the lesson using the console to create a file. i managed to resolve that finally by using "#pragma warning ( disable : 4996 )" but that doesn't help with this at all.

code included so if someone (anyone) has the patience to check it i would appreciate it.

Re: Lesson 19 - save file not being created

Posted: March 30th, 2015, 4:41 pm
by nackles
the names of these games are killing me lol

Re: Lesson 19 - save file not being created

Posted: March 30th, 2015, 6:41 pm
by Guilherme
In my computer it compile, runs and creates a file in the \Pooface EX+alpha\Chili DirectX Framework folder named hiscore.txt. The problem that I see is that you are not opening your old score so it gets reseted everytime you play the game.

Re: Lesson 19 - save file not being created

Posted: April 5th, 2015, 10:55 am
by Bumble
hey there thanks for relying

do you know where the code is wrong? would you mind being specific? or mind posting your own code so i can compare?

i really want to get this sorted so i can move on.

all and any help appreciated

Bumble :)

Re: Lesson 19 - save file not being created

Posted: April 5th, 2015, 3:07 pm
by cameron
First off you aren't loading the scores anywhere. Second off you cant save your scores in the destructor. Game is closed before it saves; destructor is for releasing memory only.

Re: Lesson 19 - save file not being created

Posted: April 5th, 2015, 7:12 pm
by albinopapa
cameron wrote:First off you aren't loading the scores anywhere. Second off you cant save your scores in the destructor. Game is closed before it saves; destructor is for releasing memory only.

The code works the way it's suppose to. Having SaveScoreboard in the destructor is perfectly legal and makes sense. Game hasn't been fully released until the destructor has completed, same goes for the constructor, the object isn't fully instantiated until the constructor has completed, not just the initializer list, but the function body as well. Creating new variables in the destructor would be a bit rediculous, but cleaning up by saving mem to disk makes sense to me.

Anyway, these are your Scoreboard functions
void ClearScoreboard();
void InsertScore( HighScore score );
void SaveScoreboard();
HighScore GetScore();

You don't have a function for reading the file and loading the previously saved scoreboard. I haven't done these tutorials in a couple years, and not even sure I did them, may have just watched and moved on. Either way, go back and watch the video skip around to see if you missed something that mentions loading / reading a data back into memory, or just move ahead.

Re: Lesson 19 - save file not being created

Posted: April 5th, 2015, 7:58 pm
by cameron
Hmm strange, I remember having issues with saving files within the dtor of classes. Maybe I had it saving the file in child dtor, when variable was declared as pointer to parent class, without destructor being virtual or something. Then again I had this issue several years ago.

Re: Lesson 19 - save file not being created

Posted: April 5th, 2015, 9:27 pm
by albinopapa
Yeah, I still don't clearly understand the virtual destructor. I'm assuming since the members of parent classes are initialized as child class members, you would destroy them in the child destructor. From what I have found though is as far as using delete or delete[] on anything created with new or new[], you can delete them anywhere as long as you only delete them once, have had issues with copies of classes deleting my heap variables of same names causing crashes when the original class gets destroyed.

Re: Lesson 19 - save file not being created

Posted: April 12th, 2015, 11:55 am
by chili
If you don't have a virtual destructor, a parent pointer to a child class will use the parent destructor to deallocate, which will create a memory leak if the child has additional data members (and could cause other problems as well).

Re: Lesson 19 - save file not being created

Posted: January 20th, 2016, 4:39 pm
by Bumble
hey thanks for the help but i managed to fix the issue. it was partly the _CRT_SECURE_NO_WARNINGS thing that was preventing VS from using the non safe versions of scanf printf etc. and partly because i had the filename wrong and didn't spot it, D'oH! thanks all. now i can finally finish the beginner lessons i started more than a year ago. :)