It works, and contained all what is needed for an highscore.
Code: Select all
; HighScore
;
; Original from STARGATE (from german forum)
; modified and extended by michel51 in Juni 2007
;
; built with Mac PB V.4.00 Beta 1
;
; tested on Mac OS X and Windwow XP
; Linux not tested, but it should run because only PB-comands are used.
;
;
Procedure ShowHighScore(File.s)
If OpenWindow(10, 0, 0, 260, 300, "Highscore", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(10))
ListIconGadget(0, 10, 10, 240, 240, "Pos", 50, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Name", 100)
AddGadgetColumn(0, 2, "Points", 60)
If ReadFile(1, File)
; ------- activate here the wished loop -----------------
; While Eof(1) = 0 ; all will be shown
For I = 1 To 10 ; only the best 10 will be shown
String.s = ReadString(1)
Name.s = Left(String, 10)
Points.s = Mid(String, 11, 5)
pos+1
AddGadgetItem(0, -1, Str(pos)+Chr(10)+Name + Chr(10) + Points)
Next ; only the best 10 will be shown
; Wend ; all will be shown
; -------------------------------------------------------
EndIf
CloseFile(1)
EndIf
EndIf
EndProcedure
Procedure HighScore(File.s, Name.s, Points.l)
If OpenFile(1, File) ; File will be opened or created.
If CreateFile(2, "_"+File) ; helpfile will be created
; ------ activate here the wished loop -----------------
; Repeat ; all will be saved
For i = 1 To 10 ; only the best 10 will be saved
String.s = ReadString(1)
HS_Points = Val(Trim(Mid(String, 11, 10)))
If HS_Points < Points And entered = 0: ; compare points
WriteStringN(2, LSet(name, 10, " ")+" "+Str(points))
entered = 1
EndIf
WriteStringN(2, String)
Next ; only the best 10 will be saved
; Until String = "" ; all will be saved
; -----------------------------------------------------
CloseFile(2)
EndIf
CloseFile(1)
EndIf
CopyFile("_"+file, file)
DeleteFile("_"+file) ; ready, Highscore is saved to file
EndProcedure
;
HSFile.s = "HScore_e.score"
; the file name should be adapted after own taste
; Example calls
HighScore(HSFile, "Test 1", 23)
HighScore(HSFile, "martin", 4)
HighScore(HSFile, "Stargate", 124)
HighScore(HSFile, "LOL", 1)
HighScore(HSFile, "baum", 2341)
HighScore(HSFile, "Namesehrlang", 55) ; very lon name for testing
HighScore(HSFile, "Klaus", 198)
ShowHighScore(HSFile) ; ... and show the highscore
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
End
Happy "Highscoring"
