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.

Newcomers DBPro Corner / Beginner's guide to dark basic book exercise: GuessingGames Program

Author
Message
VGHero11
13
Years of Service
User Offline
Joined: 15th Nov 2011
Location:
Posted: 9th Apr 2012 19:56
Hello again fellow gamers.

Well I finished another program and I seem to have typed it in correctly without any spelling errors, however when I finish the game and the program goes to record the high score (# of attempts at guessing number), it doesn't create the HIGHSCORE.DAT file and thus causes the program to exit prematurely. If someone can tell me why the file isn't being written, that would be great.



When we all lend our power together, there is nothing we
can't do!
Please Lend me your STRENGTH!
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 9th Apr 2012 20:44 Edited at: 9th Apr 2012 20:46
I just skimmed this, but I would hazard a guess and say the file is not being created due to lack of write permissions. You may wanna specify exactly where you want to write to. Usually the application's install directory or somewhere in My Documents (like using a My Documents/Appname) is usually pretty safe. Also try using GLOBAL variables to store file paths to ensure they are read/written from the same location always by using a simple reference:


Also, the way this example handles the non-existence of a high score file isn't best:

Quote: "
"


I would suggest this route (If it's not there then make it):



Remember these are just examples and many were written pre-ParanoiaEra. So, aside from lacking decent error-handling/prevention, many don't take folder permissions into account. My advice to you is to look at this and future excercises and ask "How can I improve this?". It may help you a lot with learning to think outside the box.

Good luck with your next excercise.

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 10th Apr 2012 06:32
The book is wrong. The function, CheckHighScore(Name$,Tries) has it just like you typed, but it should be equal to 0, not 1, as nonZero said. (Kindof funny, a guy named nonZero telling you the answer is zero ) When I changed it to 0 in the CheckHighScore function, the program worked fine.

Note: Look at the EnterHighScore and DisplayHighScores functions, they used 0 in those (as they should have).

So many games to code.......so little time.

VGHero11
13
Years of Service
User Offline
Joined: 15th Nov 2011
Location:
Posted: 10th Apr 2012 19:07
Thanks LBFN for finding the problem. Also thank you nonZero for those words of advice and code for creating a global variable to store high score data.

When we all lend our power together, there is nothing we
can't do!
Please Lend me your STRENGTH!
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 11th Apr 2012 02:17
yeah unfortunately the book is wrong. its like they just didnt finish the code for it. i posted here somewhere about it, but search is pretty sketchy...

Login to post a reply

Server time is: 2024-11-22 04:04:34
Your offset time is: 2024-11-22 04:04:34