How Do I Make A High Score System?

BlitzPlus Forums/BlitzPlus Beginners Area/How Do I Make A High Score System?

Cp(Posted 2008) [#1]
Problem:I want to create a high score system for my pong clone. I cant figure it out and there arent ANY examples on the web. I want it to record how many times you hit the ball in succesion,what do I need to add?

EDIT:
Writing and reading to/from a file is my problem, NOT variables. when I do that, all the scores are 0!!!


sswift(Posted 2008) [#2]
I'm a bit confused how you wrote a pong clone when you don't understand how to check to see if the current score is greater than each score in a list of high scores, or even a single high score stored in its own variable.

When I started programming, I didn't learn how to make a ball bounce off walls and a paddle until years after I learned how to keep score. :-)


Cp(Posted 2008) [#3]
I know how to keep score, its Reading/Writing the score to a file.


sswift(Posted 2008) [#4]
Ohhhh. :-)




Cp(Posted 2008) [#5]
@sswift :Thanks. Im about to try it.
EDIT:
I might have to change the code a little.
I'm recording the amount of times you hit the ball in a round, the number of rounds you won before the computer won ten,the name of the player,EDIT: and what mode, I just added endless.Do you think you could modify it a bit?
P.S. Its Rally pong,the one in the blitz showcase. Ill give you credit for the high score system if you help,please?


sswift(Posted 2008) [#6]
I think it'd be best for you to look at the code and figure out how to make those changes yourself. It's not that difficult. :-)

I'll give you a hint:

All the code is doing is writing lines of text to a text file, and then reading those lines back in. For each player it writes 3 lines, and there are 10 players. So it writes the first name, then the level, then the score, and then does the same for the next player, until it has done all players. There's nothing done different for each data type. Text and numbers are written the same way to the file. If you need to store more data for each player, just add more WriteLine and ReadLines.


Cp(Posted 2008) [#7]
Ok, ill give it a try. Im not great with the write/read routines though.
EDIT:
Erm...No savegames and levels...confused...help...:(
EDIT 2:
Fixed it to some extent,just need to display it at the title screen. could I have a hint on that(was no function for displaying in code.)
EDIT 3:
MAV.



sswift(Posted 2008) [#8]
http://acronyms.thefreedictionary.com/MAV

Monkey Attack Victim?


Cp(Posted 2008) [#9]
Memory access violation. :)


sswift(Posted 2008) [#10]
I glanced at your code, but I don't see what might have caused a MAV.


Cp(Posted 2008) [#11]
Huh. its strange...


Cp(Posted 2008) [#12]
Someone please HELP!!!


Yeshu777(Posted 2008) [#13]
Is that the code in the box a few posts above?


Cp(Posted 2008) [#14]
Yes. The latest one I posted gets a mem access violation


sswift(Posted 2008) [#15]
Um... Did you manually create a highscores.dat file, or call the save function before trying to load the highscores? Cause contrary to my comment in the code, trying to read lines from a nonexistent data file might be a bad idea.


Cp(Posted 2008) [#16]
No. I created a file in notepad and saved it. I didnt read from a non-existing file.(psst...I deleted all the code cuz I was annoyed. Its only on the forums now...)


Cp(Posted 2008) [#17]
umm...somebody help?


Yeshu777(Posted 2008) [#18]
This seems pretty straight forward:

http://www.blitzbasic.com/codearcs/codearcs.php?code=171


Cp(Posted 2008) [#19]
What do I need to change in that to make it work?
I have the amount of whacks, the score, and the name.I need a function that lets me input a name, not just read it.


Cp(Posted 2008) [#20]
YAY!!! IT WORKS!!! WOOHOO!!!!
Thanks for telling me about that yeshu!


Yeshu777(Posted 2008) [#21]
No problem.


Newcomer(Posted 2008) [#22]
Here Is How I Set HighScores


fileout1 = WriteFile("data1.dat")
WriteString(fileout1,"player1")
WriteByte(fileout1,0)
CloseFile(fileout1)

fileout2 = WriteFile("data2.dat")
WriteString(fileout2,"player2")
WriteByte(fileout2,0)
CloseFile(fileout2)

fileout3 = WriteFile("data3.dat")
WriteString(fileout3,"player3")
WriteByte(fileout3,0)
CloseFile(fileout3)

fileout4 = WriteFile("data4.dat")
WriteString(fileout4,"player4")
WriteByte(fileout4,0)
CloseFile(fileout4)

fileout5 = WriteFile("data5.dat")
WriteString(fileout5,"player5")
WriteByte(fileout5,0)
CloseFile(fileout5)

fileout6 = WriteFile("data6.dat")
WriteString(fileout6,"player6")
WriteByte(fileout6,0)
CloseFile(fileout6)

fileout7 = WriteFile("data7.dat")
WriteString(fileout7,"player7")
WriteByte(fileout7,0)
CloseFile(fileout7)

fileout8 = WriteFile("data8.dat")
WriteString(fileout8,"player8")
WriteByte(fileout8,0)
CloseFile(fileout8)

fileout9 = WriteFile("data9.dat")
WriteString(fileout9,"player9")
WriteByte(fileout9,0)
CloseFile(fileout9)

fileout10 = WriteFile("data10.dat")
WriteString(fileout10,"player10")
WriteByte(fileout10,0)
CloseFile(fileout10)


Read them Like This

filein1 = ReadFile("data1.dat")
place1$ = ReadString$(filein1)
score1 = ReadInt(filein1)
CloseFile(filein1)

filein2 = ReadFile("data2.dat")
place2$ = ReadString$(filein2)
score2 = ReadInt(filein2)
CloseFile(filein2)

filein3 = ReadFile("data3.dat")
place3$ = ReadString$(filein3)
score3 = ReadInt(filein3)
CloseFile(filein3)

filein4 = ReadFile("data4.dat")
place4$ = ReadString$(filein4)
score4 = ReadInt(filein4)
CloseFile(filein4)

filein5 = ReadFile("data5.dat")
place5$ = ReadString$(filein5)
score5 = ReadInt(filein5)
CloseFile(filein5)

filein6 = ReadFile("data6.dat")
place6$ = ReadString$(filein6)
score6 = ReadInt(filein6)
CloseFile(filein6)

filein7 = ReadFile("data7.dat")
place7$ = ReadString$(filein7)
score7 = ReadInt(filein7)
CloseFile(filein7)

filein8 = ReadFile("data8.dat")
place8$ = ReadString$(filein8)
score8 = ReadInt(filein8)
CloseFile(filein8)

filein9 = ReadFile("data9.dat")
place9$ = ReadString$(filein9)
score9 = ReadInt(filein9)
CloseFile(filein9)

filein10 = ReadFile("data10.dat")
place10$ = ReadString$(filein10)
score10 = ReadInt(filein10)
CloseFile(filein10)

and you have a HighScore System!!!


GfK(Posted 2008) [#23]
Here Is How I Set HighScores


fileout1 = WriteFile("data1.dat")
WriteString(fileout1,"player1")
WriteByte(fileout1,0)
CloseFile(fileout1)

fileout2 = WriteFile("data2.dat")
WriteString(fileout2,"player2")
WriteByte(fileout2,0)
CloseFile(fileout2)

fileout3 = WriteFile("data3.dat")
WriteString(fileout3,"player3")
WriteByte(fileout3,0)
CloseFile(fileout3)

fileout4 = WriteFile("data4.dat")
WriteString(fileout4,"player4")
WriteByte(fileout4,0)
CloseFile(fileout4)

fileout5 = WriteFile("data5.dat")
WriteString(fileout5,"player5")
WriteByte(fileout5,0)
CloseFile(fileout5)

fileout6 = WriteFile("data6.dat")
WriteString(fileout6,"player6")
WriteByte(fileout6,0)
CloseFile(fileout6)

fileout7 = WriteFile("data7.dat")
WriteString(fileout7,"player7")
WriteByte(fileout7,0)
CloseFile(fileout7)

fileout8 = WriteFile("data8.dat")
WriteString(fileout8,"player8")
WriteByte(fileout8,0)
CloseFile(fileout8)

fileout9 = WriteFile("data9.dat")
WriteString(fileout9,"player9")
WriteByte(fileout9,0)
CloseFile(fileout9)

fileout10 = WriteFile("data10.dat")
WriteString(fileout10,"player10")
WriteByte(fileout10,0)
CloseFile(fileout10)


Read them Like This

filein1 = ReadFile("data1.dat")
place1$ = ReadString$(filein1)
score1 = ReadInt(filein1)
CloseFile(filein1)

filein2 = ReadFile("data2.dat")
place2$ = ReadString$(filein2)
score2 = ReadInt(filein2)
CloseFile(filein2)

filein3 = ReadFile("data3.dat")
place3$ = ReadString$(filein3)
score3 = ReadInt(filein3)
CloseFile(filein3)

filein4 = ReadFile("data4.dat")
place4$ = ReadString$(filein4)
score4 = ReadInt(filein4)
CloseFile(filein4)

filein5 = ReadFile("data5.dat")
place5$ = ReadString$(filein5)
score5 = ReadInt(filein5)
CloseFile(filein5)

filein6 = ReadFile("data6.dat")
place6$ = ReadString$(filein6)
score6 = ReadInt(filein6)
CloseFile(filein6)

filein7 = ReadFile("data7.dat")
place7$ = ReadString$(filein7)
score7 = ReadInt(filein7)
CloseFile(filein7)

filein8 = ReadFile("data8.dat")
place8$ = ReadString$(filein8)
score8 = ReadInt(filein8)
CloseFile(filein8)

filein9 = ReadFile("data9.dat")
place9$ = ReadString$(filein9)
score9 = ReadInt(filein9)
CloseFile(filein9)

filein10 = ReadFile("data10.dat")
place10$ = ReadString$(filein10)
score10 = ReadInt(filein10)
CloseFile(filein10)

and you have a HighScore System!!!
You realise that if you learn about arrays/types, your code will be 90% shorter? Why the hell would you want ten separate files for a high score system when each file is going to allocate a minimum of 4096 bytes (4k) or hard drive space? Its awfully inefficient and a horrid way of doing it.

I appreciate that you're new and no problem with trying to help people, but you probably shouldn't dig up a 3 month old thread to post a solution to a problem that A) has already been solved, and B) your solution is a really, really bad solution.