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
cyangames
photo 2024 ... 9 11-32-24
cyangames
photo 2024 ... 9 11-32-19
cyangames
photo 2024 ... 9 11-32-15
Jayenkai
IMG 1008
Jayenkai
IMG 1009
Jayenkai
IMG 7216
Socoder
Fallout 4 ... 4 15 40 33
Socoder
Fallout 4 ... 4 15 40 55
Socoder
Fallout 4 ... 4 15 43 24
Krakatomato
Screenshot ... t 08 41 12
Undock Sidebar
ROG Ally
Jayenkai
(Sat 09:14)
Advent of Creativity 2024
Jayenkai
(Sat 04:51)
Advent 2024
Jayenkai
(Sat 04:22)
November 2024 Photo Challenge
Jayenkai
(Sat 04:04)
QOTD - November 2024
Jayenkai
(Sat 03:13)
Happy Birthday, Waroffice
Dan
(Sat 02:59)
Black Friyay!
Jayenkai
(Fri 18:08)
SnackVerse
Jayenkai
(Thu 06:29)
Spiderbots Descend
Jayenkai
(Mon 10:17)
JSE - Optimisationalism 4
Jayenkai
(Mon 07:28)
ALChoons : Recorded
Jayenkai
(Sun 17:00)
Scrolling tiles
Jayenkai
(Sat 19:53)
Would You Like a Banana?
Jayenkai
(Sat 04:44)
Happy Birthday, TomToad
Dan
(Thu 05:27)
Coke's AI Advert
Jayenkai
(Wed 02:43)
Suno/Bing Tunes
Jayenkai
(Tue 17:32)
Snow - Nov 2024
Jayenkai
(Tue 02:02)
Half Life 2 @20
Jayenkai
(Tue 01:56)
Pizza Time
cyangames
(Mon 02:38)
In Search Of Pi
steve_ancell
(Thu 22:02)
Flap Happy and Fancy Free!
cyangames
(Wed 09:52)
Bill&Ted Switch it Up
spinal
(Wed 01:21)
Amstrad Dot Com
therevillsgames
(Tue 03:33)
Poll Chat
Jayenkai
(Tue 01:25)
Showcase - Pictorial OK Tarot
Eikon
(Fri 23:03)
My Threads
|
More
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987
0|732|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.094
Highscore Functions - Socoder