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.

AppGameKit Classic Chat / hiscore saving to file

Author
Message
Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 18th Sep 2011 22:27
I'm having a bit of trouble saving higscore to a file. I'll give some code

Code:


hiscore.dat


I have explained a bit in the code, i really cant seem to find whats wrong with my code but it seems that he does not move 9 to 10 and just overwrites the highscore. It's hard to explain its behavior. Anyone can help?

Only heroes live forever
Hockeykid
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 18th Sep 2011 22:54
Quote: "FileW = OpenToWrite (file$, 0)"


Change the ",0" to ",1". 0 will make it overwrite the file and 1 will append it.

Quote from documentation:
Quote: "
append - Set to 1 to append to the file, 0 to overwrite all data (optional, default 1)."


Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 18th Sep 2011 23:02
It needs to overwrite the whole file.

It reads the code in a dim then checks for that dim if the score is bigger then one of the dimmed scores if it is it puts all current scores that are lower than the current score one place lower so the 10th best score dissapears 9th best score becomes 10th, 8th best score becomes 9th and so on. Then when its at the part where your score needs to come it puts it right there in the dim.

Then it OVERWRITES the file with the whole new dim which is what it needs to do.

Only heroes live forever
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 18th Sep 2011 23:25
I do it like this anyway

This gets wath position the user have entered!



This shuffles the others down and puts the players entry at the right place!


I have made an complete file to be used in all my games

Simply paste in the functions and voila an high score
Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 18th Sep 2011 23:46
Thanks cliff, i'll look into this tomorrow as it's time to say good night for me.

Its lesser lines than my code

I'm sure it works with some editing from my end.

Only heroes live forever
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 19th Sep 2011 01:06 Edited at: 19th Sep 2011 01:09
Yes but this is only parts of my high score code

You only wanted help with getting the player entry in the right place and to shuffle down the lower scores?

If it dont work so could you try my complete file !

This is still work in progress for me but it works!



Cheers......

Ps...... if you scroll the view offset so must you reset it back to o,o or the agk input window will not always show up!
Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 19th Sep 2011 19:59
The first part was exactly what i was looking for. In your second part i have a tip for ya.

Type HScore
name$
nr
Endtype

dim HighScore[5] as Hscore

and then change every HighScoreNR to Highscore.nr and HighScoreName$ to Highscore.name$

Its not that your part is wrong but i think it's neater code.

Gonna add your first part to my code now and test it out.

Only heroes live forever
Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 19th Sep 2011 20:36
Just tested it and made it so that it works with my code.

Again thanks alot Cliff

Only heroes live forever
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 19th Sep 2011 23:49 Edited at: 20th Sep 2011 01:13
Quote: "Type HScore
name$
nr
Endtype

dim HighScore[5] as Hscore

and then change every HighScoreNR to Highscore.nr and HighScoreName$ to Highscore.name$

Its not that your part is wrong but i think it's neater code.

Gonna add your first part to my code now and test it out."

Thanks for the input
I whas still working on it but it works !
Will probably add that later on

Quote: "Just tested it and made it so that it works with my code.

Again thanks alot Cliff"

We are here to help each other

Updated the read and write function in to one today also!
Saves some lines of bytecode

Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 20th Sep 2011 10:30
There is no need to keep putting stuff like this in your code:


Just do this:
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 20th Sep 2011 22:07 Edited at: 20th Sep 2011 22:16
Does the exit function command work in the agk ?

I tryed to use it in the beginning but it read the entire function anyway

But that whas in the first release

Thanks bursar are going to check if it works now ?

I actually hate the goto command

Edited................
I knew there whas a reason i used it

exit function uses more lines of bytecode then the 2 lines neaded for the goto function
Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 20th Sep 2011 22:10
I do it even different still.. May not be useful to you now, but it's how I handle it.

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 20th Sep 2011 22:18
I belive your version is slightly faster ?

Thanks for the input

Login to post a reply

Server time is: 2024-11-22 05:30:06
Your offset time is: 2024-11-22 05:30:06