Hi scores shuffle
Blitz3D Forums/Blitz3D Beginners Area/Hi scores shuffle
| ||
I have a high score table in my game. However, when I try to insert a score into the table, although it appears in correct place, and the scores above are right, any that follow are not right can anyone see where I have gone wrong?position=0 For f=10 To 1 Step-1 number=(hiscoredata$(f,2)) If score>number position=f EndIf Next If position>0 For f=(position) To 9 hiscoredata$(f,1)=hiscoredata$(f+1,1) hiscoredata$(f,2)=hiscoredata$(f+1,2) Next hiscoredata$(position,1)=name$ hiscoredata$(position,2)=score ffile=WriteFile("HSTable.SCO") For f=1 To 10 WriteLine ffile,hiscoredata$(f,1) WriteLine ffile,hiscoredata$(f,2) Next EndIf I know it's to do with this section: If position>0 For f=(position) To 9 hiscoredata$(f,1)=hiscoredata$(f+1,1) hiscoredata$(f,2)=hiscoredata$(f+1,2) Next hiscoredata$(position,1)=name$ hiscoredata$(position,2)=score but I can't see how to correct it - (I gess it's the heat :) ) |
| ||
Ah got it. It shold have been: hiscoredata$(f+1,1)=hiscoredata$(f,1) hiscoredata$(f+1,2)=hiscoredata$(f,2) |
| ||
Now I have the high scores under the new one repeated: i.e. 10000 AAA 9000 BBB 8000 CCC 7500 Test 7000 DDD 7000 DDD 7000 DDD 7000 DDD 7000 DDD 7000 DDD |
| ||
What I did for my high score table was : - check if the score belongs on the table - if it does, overwrite the bottom row of the table with the new score - sort the table Seemed simpler than trying to figure out which position it belongs in and reshuffling all the indices. |
| ||
Yeah. EpicBoys approach is definately the "less hassle" way. |
| ||
Malice, Just work it from the bottom to the top and it will work. [code]If position>0 For f=9 to (position) step -1 hiscoredata$(f+1,1)=hiscoredata$(f,1) hiscoredata$(f+1,2)=hiscoredata$(f,2) Next hiscoredata$(position,1)=name$ hiscoredata$(position,2)=score [code] |
| ||
doh!!! I really am gonna blame the heat on this one :) |
| ||
Or look at my website (www.blitzbasic.no) for a complete hightscore system :) Lets's say you display 20 highest scores. Just insert the new score at 21 and sort and you're all set. |