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 AppGameKit Corner / High Score Saving / Loading Question

Author
Message
nickshepherd
11
Years of Service
User Offline
Joined: 19th Jun 2013
Location: The Land of Game Development
Posted: 1st Aug 2016 21:32
I am trying to write a high score to a file when the high score is greater than the previous one, and display the high score as text. However, whenever I run this code, I get a reading of 0 even if the score is above 0. Can anyone please tell me where I'm going wrong? I'm a newbie to writing and opening files... Thank you!

Highscore as integer
If lives = 0 and highscore > score
highscore = score
opentowrite(1, "high_score.dat")
writeinteger(1, highscore)
closefile(1)
Endif
if GetFileExists("high_score.dat") = 1
File = OpenToRead("High_Score.dat")
HighScore = ReadInteger(1)
CreateText(27, str(highscore))

-Nick Shepherd
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 2nd Aug 2016 06:00
Shouldn't this:

...be this?
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 2nd Aug 2016 16:59 Edited at: 2nd Aug 2016 17:01
or this..


Wouldn't we also need to read the file first to assign the existing highscore's value before we make the comparison?

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
nickshepherd
11
Years of Service
User Offline
Joined: 19th Jun 2013
Location: The Land of Game Development
Posted: 4th Aug 2016 02:58 Edited at: 4th Aug 2016 04:15
I changed "If lives = 0 and highscore < score" to "If lives = 0 and highscore > score". That was the issue! I was staring at the screen too long... Thank you so much JLMoondog and Conjured!
-Nick Shepherd
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 4th Aug 2016 14:10
not sure if it matters or not with AppGameKit but you have also put a capital H in this line
Quote: "File = OpenToRead("High_Score.dat")"
life\'s one big game
spec= 2.6ghz, 1gb ram, 512mb gpu, directx 9.0c, dbpro and classic
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 4th Aug 2016 22:14
It'll matter on mobile, not so much on pc. But better safe than sorry though.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th Aug 2016 23:25
Have you looked at this?

https://forum.thegamecreators.com/thread/210569

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
nickshepherd
11
Years of Service
User Offline
Joined: 19th Jun 2013
Location: The Land of Game Development
Posted: 12th Aug 2016 03:34
I hadn't looked at that! Sounds very interesting; I'll be signing up soon. Thanks for sharing Phaelax.
-Nick S.

Login to post a reply

Server time is: 2024-11-24 11:19:37
Your offset time is: 2024-11-24 11:19:37