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
Jayenkai
IMG 0981
Jayenkai
Kavokian
cyangames
JSE Screen ... 0 17-57-46
spinal
explode ef ... ect 01 mp4
Jayenkai
Photo on 1 ... 15 41 jpg
Jayenkai
IMG 7186
Jayenkai
IMG 0927
spinal
Warehouse ... -53-08 mp4
spinal
Warehouse ... -39-27 mp4
steve_ancell
IMG 202411 ... 194442 344
Undock Sidebar
ROG Ally
spinal
(Thu 12:27)
Happy Birthday, TomToad
Dan
(Thu 05:27)
November 2024 Photo Challenge
Jayenkai
(Thu 03:15)
QOTD - November 2024
Jayenkai
(Thu 02:09)
JSE - Optimisationalism 4
cyangames
(Wed 11:01)
Coke's AI Advert
Jayenkai
(Wed 02:43)
Suno/Bing Tunes
Jayenkai
(Tue 17:32)
SnackVerse
Jayenkai
(Tue 16:03)
Snow - Nov 2024
Jayenkai
(Tue 02:02)
Half Life 2 @20
Jayenkai
(Tue 01:56)
Scrolling tiles
Jayenkai
(Mon 17:00)
Pizza Time
cyangames
(Mon 02:38)
ALChoons : Recorded
Jayenkai
(Sat 16:29)
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)
Greenie's Typing Tutorium
Jayenkai
(Mon 18:15)
Are Filesizes Important?
Dan
(Mon 06:55)
Spiderbots Descend
cyangames
(Mon 03:23)
Xmas Jumpers
Jayenkai
(Fri 17:33)
Site Tweaks - Oct 2024
Jayenkai
(Wed 03:54)
What's A Good 3D Modeller
Jayenkai
(Tue 04:28)
Showcase - Pictorial OK Tarot
Eikon
(Fri 23:03)
My Threads
|
More
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987
0|518|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.098