How Do I Make A High Score System?
BlitzPlus Forums/BlitzPlus Beginners Area/How Do I Make A High Score System?
| ||
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!!! |
| ||
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. :-) |
| ||
I know how to keep score, its Reading/Writing the score to a file. |
| ||
Ohhhh. :-) |
| ||
@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? |
| ||
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. |
| ||
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. |
| ||
http://acronyms.thefreedictionary.com/MAV Monkey Attack Victim? |
| ||
Memory access violation. :) |
| ||
I glanced at your code, but I don't see what might have caused a MAV. |
| ||
Huh. its strange... |
| ||
Someone please HELP!!! |
| ||
Is that the code in the box a few posts above? |
| ||
Yes. The latest one I posted gets a mem access violation |
| ||
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. |
| ||
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...) |
| ||
umm...somebody help? |
| ||
This seems pretty straight forward: http://www.blitzbasic.com/codearcs/codearcs.php?code=171 |
| ||
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. |
| ||
YAY!!! IT WORKS!!! WOOHOO!!!! Thanks for telling me about that yeshu! |
| ||
No problem. |
| ||
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!!! |
| ||
Here Is How I Set HighScores 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.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!!! 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. |