Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 14:16 04 Dec 2022 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: High Score handling reusable library

Author Message
mkopack73
Senior Member

Joined: 03/07/2020
Location: United States
Posts: 261
Posted: 01:11am 04 Aug 2020
Copy link to clipboard 
Print this post

Here you go gang...

I've put together a reusable .inc library for handling High scores.

It supports both integer and time based scoring, with both high and low = better score arrangements.

API:


' use this to load in the high score data from the given filename. Also sets up the type of scoring system. If the file doesn't exist, it will create an empty data table
' scoretype = 0 for integer scores, 1 for time based (in MS),
' highbetter = 0 for lower is better, 1 for higher is better
sub loadhighscores (filename as String, scoretype as integer, highbetter as integer)


' call this to show the high scores. Set the font, scale, color and page BEFORE calling this function
sub displayscores ()


' call this with the score to see if it's in the top 10 list
' returns position if it is a high score, 0 if it's not
' if the score is a time, express it in milliseconds
function checkishigh (score as integer)


' shows text for capturing the player's name. Once entered the updated top-10 is saved to disk using the filename set during the load
' set the font, scale, color and page BEFORE calling this function.
' score is the new score data (if it is a time, express it in milliseconds as a string
' position is the slot for the new score (get this from checkishigh())
sub capturename (score as string, position as integer)


Note, the code (as it currently stands) depends upon OPTION BASE 1 being set (because I grew up with BASIC array indexes always starting at 1!!!)

I tested using the 2 functions (included in the code with the calls to them commented out) so if you're not sure how to use things, look at those. As stated, be sure to set your screen, font and font scaling, and clear the screen before/after the functions. Also, I did my testing using mode 1,8 with font 2,2, so you might want to play with the layout and such to fit your needs.

NOTE: the capturename() needs to be on screen 0 otherwise you won't be able to see what you're typing in. But if you need it to work otherwise, feel free to modify it to fit your needs.

Enjoy and let me know in this thread if you have any questions or problems... Feel free to use this any way you wish, I just ask that you include some kudos to me if the readme or comments of your code or about for your game...

Code Here
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2022