Log In  


Cart #56838 | 2018-09-18 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
13

I put this together for a game I'm working on, but I thought it might be useful to folks as a standalone cart. The code is clearly segregated between the demo and the actual high score code, so should be easy to lift and shift, or feel free to adapt as you like.

To try the demo: left and right increase/decrease the score, up checks the score against the high score table and switches to score entry if your score is high enough.

Features:

  • Large score support (from the discussion here: https://www.lexaloffle.com/bbs/?tid=3577 )
  • "Fancy" High score table display
  • Inline entering of high score name (3 characters to fit in with the 80s/90s game vibe, but could be extended easily enough)
  • Persistence of the save data (uses dget and dset, I know you can store more using alternative methods, but I believe you then lose that data if the cartridge is updated)

Haven't needed to worry too much about token counts yet - its not a huge amount of code as it is, but I might optimise it a bit more in the future, but I don't want to impact the readability.

13


This is really good. Can you now make it using the command scoresub(cart_id, table[, score[, extra]]) ?

scoresub is a command available in PICO-8 but i haven't seen anyone making use of it yet.


What does that do? The (little) info I can find from searching seems to imply it uploads your high scores to the bbs somehow? How do you then view/compare with others?


I don't know, GrumpyDev ... Don't be grumpy. :)

I just found out about the command myself yesterday. When I read the title of this cart I was hoping it was making use of it.

It may be something ZEP hasn't finished yet.


Heh, my name just forewarns people of potential grumpyness :P

Yeah, although the command works, it doesn't seem to actually show anywhere, I'm guessing it needs at least a BBS update to show other people's scores.


Well you've got a cool high-score routine anyways, Grumpydev.

I like the way your cart chooses a vertical quadrant where you enter your name right there on the screen, instead of default at the bottom and after name entry, making it appear at the top.

I might recommend you NOT use TABS in your coding though as if you try to search for something with CTRL+F, unless you are IN that tab, it will NOT show up in a search.

Hopefully ZEP will fix this next release.


1

I only added the tab to help split the demo code from the actual high score code, I don't use them in my normal stuff, although I do my actual coding in VSCode anyway :)


1

scoresub() isn't implemented yet! It was meant as a placeholder for future compatibility, but will be functional from 0.2.0.


Yay ! Sounds good, ZEP. Was hoping you weren't napping. You're on top of the convos in here so that's good.


Just wanted to say thanks for sharing this code! With a little bit of tweaking I was able to slot it nicely into my game (even if I was very confused at first why my scores were multiplied by 65,536!)


FTR Ctrl-F searches for something in current code tab, Ctrl-G finds next matches, Ctrl-H finds next matches in all tags.


That's a great tip merwok! I've always found the Ctrl + F search limited, so I usually open my code in Notepad to see it all. I'll use this in future!


1

How can i delete all records for new game? And is it possible to work with an ever narrower change, like an ever shorter time?


1

Possibly the answer:

Reset all highscores:

The easiest way to reset all highscores is to call the load_scores function if the stored "magic_number" does not match the one in high_score_table. This is already done in the code. To reset all highscores manually, you can change the "magic_number" and then call load_scores.

However, if you want to have a separate function for this, you can add the following code:

lua

function high_score_table.reset_scores()
for i=1,10 do
high_score_table.scores[i] = { name = "aaa", score = shr((11000-i*1000),16)}
end
high_score_table.save_scores() -- this saves the reset values
end

You can call this function whenever you want to reset the high scores.

A record for the shortest time:

If the record is to complete a task in the shortest possible time (such as a race), then you need to change the logic in the check_current_score function. Instead of checking if the current score is greater than the saved score, check if it is less.

Change the code in the check_current_score function from:

lua

if (high_score_table.current_score > high_score_table.scores[i].score) then

to:

lua

if (high_score_table.current_score < high_score_table.scores[i].score) then

Now the high score table entry will be updated if the current score (i.e. time) is shorter than the previously saved time.

These are the changes you need to make to meet your requirements. Please note that you should test the code thoroughly after making these changes to make sure that everything works as expected.



[Please log in to post a comment]