Highscore Functions - Socoder
Undock Sidebar
Home
Forum
Showcases
Articles / Tutorials
Code Snippets
Links
Blogs
Newsletter
Wed. Workshop
Search
FAQs
About
Member List
Dev Tools
Log in
Username
Password
Log In
Forgot your Password?
Register
Username
Email
Register
Recent Uploads
spinal
angry dialog 01 test
spinal
angry dialog 01 test
spinal
glasses test
steve_ancell
IMG 202404 ... 104348 349
cyangames
snaphappy
Pakz
IMG 3178Spritegen
Pakz
IMG 0460Userint
spinal
nerdly error 1
spinal
blitz3d error array
Pakz
pixelArtPoster26x6
Undock Sidebar
QOTD - May 2024
Jayenkai
(Sat 01:46)
Early 2024 Flu
Jayenkai
(Sat 00:31)
AGameAWeek 2024
steve_ancell
(Fri 10:57)
VidGen 2
Jayenkai
(Fri 09:10)
Showcase - Emu's Massive Hunt [Vic 20 +35K]
Jayenkai
(Fri 03:03)
JSE - Game of Life
AndyH
(Fri 02:41)
Happy Birthday, BASIC
AndyH
(Fri 02:00)
ALChoons : Zinc
Jayenkai
(Thu 22:55)
Knuckles the Series
Jayenkai
(Thu 05:16)
Flap Happy and Fancy Free!
cyangames
(Wed 15:40)
Suno/Bing Tunes
Jayenkai
(Wed 09:21)
Showcase - EikOS
cyangames
(Wed 01:48)
Benefactor Music Playlist. (CD32)
Jayenkai
(Tue 05:34)
QOTD - April 2024
steve_ancell
(Tue 04:54)
Apple Event - May 2024
Jayenkai
(Tue 03:15)
Time Travel Recommendations
Jayenkai
(Mon 07:56)
A.I.Am a Good Driver
cyangames
(Sun 14:50)
JSE Transpiler?
Jayenkai
(Thu 11:36)
Stable Diffusion 3
Jayenkai
(Sat 13:32)
Poe Subscriptions
Jayenkai
(Sat 13:24)
Happy Birthday, Qube
Pakz
(Sat 07:15)
Meta Quest 3
therevillsgames
(Fri 18:39)
Poll Chat
Dan
(Wed 12:47)
Scrolling tiles
spinal
(Wed 11:54)
Blitz3D v1.111
Jayenkai
(Wed 05:23)
My Threads
|
More
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987
0|103|0
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder
->
Snippet Home
->
Misc
MikeT
Created : 12 December 2006
System : Windows
Language : Blitz
Highscore Functions
Functions for loading,saving,sorting etc. highscores
here's the functions..
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Highscores Handling procs ;; ;; by Mike Tilley ;; ;; Sunset Kangaroo 2006 ;; ;; ;; IMPORTANT ALL SCORES ARE INTEGERS AND ALL NAMES ARE STRINGS ;; please see attached example of use ;; ;; Functions ;; ;; **************************************************************** ;; setupHighscores(file$) ;; sets up highscore file. ;; args: file$ is name of file ;; IMPORTANT please look at function and ammend the table as you need ;; ****************************************************************** ;; ;; ****************************************************************** ;; sortHighscores(player$,pscore) ;; sorts highscores into order. ;; args: player$ is player name, pscore is player score ;; ****************************************************************** ;; ;; ****************************************************************** ;; checkHighscores(pscore) ;; checks highscores to see if players score is worthy of entry ;; and returns true if it is or false if it isn't ;; args: pscore is the player score ;; used like this : ;; If checkHighscores(player_score)=True Then ;; do whatever - e.g. get players name ;; sortHighscores(player_name$,player_score) ;; End If ;; ****************************************************************** ;; ;; ****************************************************************** ;; deleteHighscores() ;; deletes all highscore types from memory ;; ****************************************************************** ;; ;; ****************************************************************** ;; saveHighscores(file$) ;; saves highscores to file. ;; args: file$ is name of file ;; ****************************************************************** ;; ;; ****************************************************************** ;; loadHighscores(file$) ;; loads highscores from file. ;; args: file$ is name of file ;; ****************************************************************** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Const tablesize=10; 10 is size of table Change this to change size of table Type Highscore Field name$ Field score End Type ;; change number in brackets to have diffent size score table ;; must match size in setupHighscores Global hi.Highscore Dim highscores.Highscore(tablesize) ;; sets up highscore file. ;; args: file$ is name of file Function setupHighscores(file$) ;; if file doesn't exist then set up a new highscore table and file If Not FileType(file$)=1 Then fileout=WriteFile(file$) ;************************************************************** ;;put whatever scores and names you want in here ;;for larger or smaller tables add or remove pairs of lines ;; must have same number of entries as tablesize const above WriteString(fileout,"Mike1") WriteInt(fileout,10000) WriteString(fileout,"Mike2") WriteInt(fileout,8000) WriteString(fileout,"Mike3") WriteInt(fileout,7000) WriteString(fileout,"Mike4") WriteInt(fileout,6500) WriteString(fileout,"Mike5") WriteInt(fileout,6000) WriteString(fileout,"Mike6") WriteInt(fileout,5000) WriteString(fileout,"Mike7") WriteInt(fileout,3500) WriteString(fileout,"Mike8") WriteInt(fileout,3000) WriteString(fileout,"Mike9") WriteInt(fileout,2000) WriteString(fileout,"Mike10") WriteInt(fileout,1000) ;********************************************************* CloseFile(fileout) EndIf End Function ;; loads highscores from file. ;; args: file$ is name of file Function loadHighscores(file$) filein=ReadFile(file$) For a = 1 To tablesize hi.Highscore=New Highscore hi\name$=ReadString(filein) hi\score=ReadInt(filein) Next CloseFile(filein) End Function ;; saves highscores to file. ;; args: file$ is name of file Function saveHighscores(file$) fileout=OpenFile(file$) While num <tablesize For hi.Highscore=Each Highscore WriteString(fileout,hi\name$) WriteInt(fileout,hi\score) num=num+1 Next Wend CloseFile(fileout) deleteHighscores() End Function ;; sorts highscores into order. ;; args: player$ is player name, pscore is player score Function sortHighscores(player$,pscore) tempname$="" tempscore=0 For hi.Highscore=Each Highscore If pscore>=hi\score Then tempname$=hi\name$ tempscore=hi\score hi\name$=player$ hi\score=pscore player$=tempname$ pscore=tempscore End If Next End Function ;; checks highscores to see if players score is worthy of entry ;; and returns true if it is or false if it isn't ;; args: pscore is the player score ;; used like this : ;; If checkHighscores(player_score)=True Then ;; do whatever ;; sortHighscores(player_name$,player_score) ;; End If Function checkHighscores(pscore) yes=False For hi.Highscore=Each Highscore If pscore>=hi\score Then yes=True End If Next Return yes End Function ;; deletes all highscore types from memory Function deleteHighscores() Delete Each Highscore End Function
--v
and heres a quick example of their use....
Include "highscorefunctions.bb" Graphics 640,480,32,2 Const name$="Fred" ; name for testing Const score=5500 ; score for testing setupHighscores("Hightest.dat") loadHighscores("Hightest.dat") Print"set up table" Print For hi.Highscore=Each Highscore Print(hi\name$)+" "+(hi\score) Next If checkHighscores(score)=False Then Print Print("not changed") saveHighscores("Hightest.dat") End If If checkHighscores(score)=True Then Print Print("changed") sortHighscores(name$,score) saveHighscores("Hightest.dat") End If Print Print"new table" Print loadHighscores("Hightest.dat") For hi.Highscore=Each Highscore Print(hi\name$)+" "+(hi\score) Next Print Print"Press any key to exit" WaitKey()
--v
hope they help someone out. If you do end up using them in a game please give me a little credit
- ta
Comments
Copyright
Jayenkai
- 2017+ | Thanks to
Shroom_Monk
for CSS/Dev Tips | Uses a Jay-Tweaked version of
CBParser
.
Page Took : 0.201
Highscore Functions - Socoder