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
JSE Transpiler?
Jayenkai
(Tue 11:39)
Flap Happy and Fancy Free!
Jayenkai
(Tue 10:37)
QOTD - April 2024
cyangames
(Tue 03:12)
Suno/Bing Tunes
spinal
(Tue 02:02)
VidGen 2
Jayenkai
(Mon 10:17)
Time Travel Recommendations
Jayenkai
(Sun 00:21)
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)
ALChoons : Zinc
Jayenkai
(Wed 13:00)
Poll Chat
Dan
(Wed 12:47)
Scrolling tiles
spinal
(Wed 11:54)
AGameAWeek 2024
Jayenkai
(Wed 06:51)
Blitz3D v1.111
Jayenkai
(Wed 05:23)
Udio Tunes
Jayenkai
(Tue 07:36)
Showcase - Bubble Bobble RPG
Eikon
(Sun 20:44)
Blue Man Group
Jayenkai
(Sun 15:03)
Blogs - JayWalking
Jayenkai
(Sat 06:53)
Steve's Car
steve_ancell
(Sat 03:19)
Stuck in a Rut
triptych
(Fri 13:49)
Space Discoveries
therevillsgames
(Thu 01:24)
Happy Birthday, jprofitt
steve_ancell
(Wed 14:28)
Happy Birthday, steve_ancell and blanko1324
steve_ancell
(Mon 23:44)
Link - Who remembers Barry Scott?
cyangames
(Mon 23:13)
My Threads
|
More
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987
0|575|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.206
Highscore Functions - Socoder