ID:169198
 
Basically, I have no clue what to do with savefiles. I am working with an idea of trying to get scores to print to the screen, so that byond or telnet users can see them. I'm really lost though. I don't know what to do, someone please help and I'll be your best friend...sort of...
var/fst = 0
var/scd = 0
var/thd = 0
var/frth= 0
var/fifth=0
var/sixth=0
var/svnth=0
var/eighth=0
var/ninth=0
var/tenth=0


mob/proc/savehighscore()
var/savefile/F = new("highscore.sav") //Access the savefile
if(usr.score>fst)
usr.score = fst
usr<<"You're <b>first</b> on the high score!"
F["1st"] << fst
else if(usr.score>scd)
usr.score = scd
usr<<"You're <b>second</b> on the high score!"
F["2nd"] << scd
else if(usr.score>thd)
usr.score = thd
usr<<"You're <b>third</b> on the high score!"
F["3rd"] << thd
else if(usr.score>frth)
usr.score = frth
usr<<"You're <b>fourth</b> on the high score!"
F["4th"] << frth
else if(usr.score>fifth)
usr.score = frth
usr<<"You're <b>fifth</b> on the high score!"
F["5th"] << fifth
else if(usr.score>sixth)
usr.score = sixth
usr<<"You're <b>sixth</b> on the high score!"
F["6th"] << sixth
else if(usr.score>svnth)
usr.score = svnth
usr<<"You're <b>seventh</b> on the high score!"
F["7th"] << svnth
else if(usr.score>eighth)
usr.score = eighth
usr<<"You're <b>eighth</b> on the high score!"
F["8th"] << eighth
else if(usr.score>ninth)
usr.score = ninth
usr<<"You're <b>ninth</b> on the high score!"
F["9th"] << ninth
else if(usr.score>tenth)
usr.score = tenth
usr<<"You're <b>tenth</b> on the high score!"
F["10th"] << tenth







mob/proc/readhighscore()
var/savefile/F = new("highscore.sav") //Access the savefile
usr<<"\tHigh Scores \n "
F["1st"] >> fst
F["2nd"] >> scd
F["3rd"] >> thd
F["4th"] >> frth
F["5th"] >> fifth
F["6th"] >> sixth
F["7th"] >> svnth
F["8th"] >> eighth
F["9th"] >> ninth
F["10th"] >> tenth
Look up Raekwon's demo of scoreboards + learn about savefiles in ByondBwicki.
In response to DeathAwaitsU
DeathAwaitsU wrote:
Look up Raekwon's demo of scoreboards

Don't. In addition to not even compiling, Raekwon's demo is almost completely uncommented.
Please look at the following two articles (in order):
Also, instead of those 10 variables, you should really be using an associative list in the format [key] = [score]. For that, check out these two articles (again, in order):

A good rule of thumb is that if you find yourself typing the same piece of code out over and over again, you probably don't have to.
In response to Wizkidd0123
And it really wouldn't help the telnet users, which is why I want it to print in text.
In response to Wizkidd0123
Well, I changed a little of it...I'm still shooting in the dark after reading those things...
var/fst = 0
var/scd = 0
var/thd = 0
var/frth= 0
var/fifth=0
var/sixth=0
var/svnth=0
var/eighth=0
var/ninth=0
var/tenth=0



mob/proc/savehighscore()
var/savefile/F = new("highscore.sav") //Access the savefile
if(src.score>fst)
src.score = fst
src<<"You're <b>first</b> on the high score!"
F["1st"] << fst
else if(src.score>scd)
src.score = scd
src<<"You're <b>second</b> on the high score!"
F["2nd"] << scd
else if(src.score>thd)
src.score = thd
src<<"You're <b>third</b> on the high score!"
F["3rd"] << thd
else if(src.score>frth)
usr.score = frth
usr<<"You're <b>fourth</b> on the high score!"
F["4th"] << frth
else if(src.score>fifth)
src.score = frth
src<<"You're <b>fifth</b> on the high score!"
F["5th"] << fifth
else if(src.score>sixth)
src.score = sixth
src<<"You're <b>sixth</b> on the high score!"
F["6th"] << sixth
else if(src.score>svnth)
src.score = svnth
src<<"You're <b>seventh</b> on the high score!"
F["7th"] << svnth
else if(src.score>eighth)
src.score = eighth
src<<"You're <b>eighth</b> on the high score!"
F["8th"] << eighth
else if(src.score>ninth)
src.score = ninth
src<<"You're <b>ninth</b> on the high score!"
F["9th"] << ninth
else if(src.score>tenth)
src.score = tenth
src<<"You're <b>tenth</b> on the high score!"
F["10th"] << tenth








mob/proc/readhighscore()
var/savefile/F = new("highscore.sav") //Access the savefile
src<<"\tHigh Scores \n "
F["1st"] >> fst
F["2nd"] >> scd
F["3rd"] >> thd
F["4th"] >> frth
F["5th"] >> fifth
F["6th"] >> sixth
F["7th"] >> svnth
F["8th"] >> eighth
F["9th"] >> ninth
F["10th"] >> tenth
var/t
for(t in F)
src<<"[t]"
In response to Wizkidd0123
Please, explain how to save associative lists! Or what the heck I'm actually supposed to be doing! Please!
In response to Draxxis
Correct me if I'm wrong but shouldn't "src.score=fst" be more like "fst=src.score" if the score and fst are indeed num(s)...?
In response to ManDroid13
I know it's been over 3 years, but has anyone got this to work? This seems like the ideal Highscores that I want for my game. Anyone?

Any help would be greatly appreciated!

-Shake
In response to Xx mAsTa_sHaKe xX
I posted one for PHP/MySQL:
http://www.byond.com/members/ GhostAnime?command=view_post&post=46866

But a simple one can be programmed in DM... I am just too lazy to do that.
In response to GhostAnime
Looks nice, but I don't wanna deal with a PHP mess lol, I think if I could find out the problem with this one I could use it.
In response to Xx mAsTa_sHaKe xX
/*
Highscore Table - DM version!
Made by: GhostAnime
Made on: Sept 13/08

WARNING: NOT TESTED
*/


var/list/highscore // Defining a list variable globally without initiation. Assume the entry is listed as ("cKey" = Level, "cKey2" = Lower Level, etc)

world
New() // When the game starts
..() // Without this... well, try seeing what'll happen
var/savefile/F=new("highscore.sav") // Creates a new /savefile instance. First it looks for the file "highscore.sav" in the main directory. If not there, a new one will be created
F["score"] >> highscore // Loads the saved high score list()
if(!highscore) // If highscore is null (such as loading null from the highscore not being in the savefile initially)
highscore = list() // Makes it a list() so runtime errors can be avoided. Without this, and highscore = null from the loading... well, you're get RTEs

Del() // When the game (properly) shuts down
..()
var/savefile/F = new("highscore.sav")
F["score"] << highscore // Saves the highscore list(). It is wise to make this a general procedure and call it whenever the highscore variable is modified - so, in case any crashes happens - the highscore table remains accurate.

// The following is a situational example and this method is not the best. There are better methods of sorting out there.

mob/proc/LevelUp()
var/old_level = src.level // You'll see why soon.
while(src.exp >= src.max_exp) // In case someone got more experience then the next level
src.level += 1 // Level increases by one... I could have done src.level++ but meh
src.exp -= src.max_exp // Removing the exp for the level
src.max_exp *= 2 // Increases max_exp by 2X... note that exp does not equal 0 ... yet. This loop will repeat if the amount of exp left exceeds this increase.
if(src.level > old_level) // If the person actually leveled up
src.exp = 0 // Experience is set to 0, because I can.
. = cKey(src.key) // You'll find out why soon
if(. in highscore) // If they are already in the high score table
highscore -= . // Bye bye.
. = 1 // You'll find out why soon enough.
for(var/A in highscore) // Looping through the values in the list (please see comment at the variable definition)
.++ // Increases the list position
if(highscore[A] < src.level) // If (finally) a high score value is found where the last level entry is lower
. -= 1 // So we can insert the entry before the lower level
break // No more searching!
// If there was no entries, the for() is not called, thus the person shall be in the first position
highscore.Insert(.,list(cKey(src.key) = src.level)) // Inserts the entry.
Call_Highscore_Save_Proc()


Remember, untested and rather brief (skeleton) points of how it could be done.

There are better methods out there though.
In response to GhostAnime
At this point I don't care if that works... the fact that you just made it that quickly has me still trying to pick my jaw off of the floor. I will definitely test it out. Thanks (I may come back if I have problems.)
In response to Xx mAsTa_sHaKe xX
It wasn't difficult as you may think.

You have to take things systematically and I will show you what I did:

1) Define the variable to keep track of the high score (this should be a given).

2) Set it up so you can save/load the highscore table.

3) Program in how you want the entry to be.


Three simple steps, it may look long and complex but it was rather quite simple and straight-forward.
In response to GhostAnime
mob/proc/scoring()
var/old_level = src.level // You'll see why soon.
while(src.exp >= src.max_exp) // In case someone got more experience then the next level
src.level += 1 // Level increases by one... I could have done src.level++ but meh
src.exp -= src.max_exp // Removing the exp for the level
src.max_exp *= 2 // Increases max_exp by 2X... note that exp remains the same though.
if(src.level > old_level) // If the person actually leveled up
src.exp = 0 // Experience is set to 0, because I can.
/*>>>>*/ = cKey(src.key) // You'll find out why soon
if(. in highscore) // If they are already in the high score table
highscore -= . // Bye bye.
= 1 // You'll find out why soon enough.
for(var/A in highscore) // Looping through the values in the list (please see comment at the variable definition)
.++ // Increases the list position
if(highscore[A] < src.level) // If (finally) a high score value is found where the last level entry is lower
-= 1 // So we can insert the entry before the lower level
break // No more searching!
highscore.Insert(.,list(cKey(src.key) = src.level)) // Inserts the entry.
Call_Highscore_Save_Proc()



Definitely a lot of indentation errors thoughout it all, but I fixed all of those now all I need to know what to do where I put the arrows... it says I'm missing the left hand argument
In response to Xx mAsTa_sHaKe xX
Ok, I'm sorry Ghost that was just stupid of me... >.<

I should've looked closer... YOU ROCK!