Ooops
February 19, 2020, 02:15:00 AM

Author Topic: High Score Explanation  (Read 420 times)

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
High Score Explanation
« on: February 07, 2020, 10:08:46 AM »
Hello!
I wanted to create a highscore list for my shmup and tried to extract code from the digesteroids example coming with blitzmax. I failed.
Now i want some tutorials but can't find them

Do you have any idea where i should start?

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #1 on: February 07, 2020, 02:06:52 PM »
- have a list (eg TList) to store the entries
- create a Type THighscoreEntry
- - field score:Long
- - field name:String
- use "Method Compare:int(otherobject:object)" within THighscoreEntry to override sorting behaviour
- in that method:
- - cast "otherobject" to be of the type of interest: "local entry:THighscoreEntry = THighscoreEntry(otherObject)"
- - return 0 if entry = null (not of the right type)
- - return 1 if self.score > entry.score
- - return -1 if self.score < entry.score
- - return 0 if scores are the same (or maybe then compare names
- when adding highscores: add it to the list, sort the list, and if list.count() > your limit, then "while list.count() > limit; list.RemoveLast(); wend"


This should be enough to "start" (I assume you want to tinker around with it on your own instead of using a premade solution).


bye
Ron

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #2 on: February 08, 2020, 07:19:59 AM »
Thank you very much for your time and support!

I do not understand this:
- when adding highscores: add it to the list, sort the list, and if list.count() > your limit, then "while list.count() > limit; list.RemoveLast(); wend"

Maybe you could provide me with
a premade solution? I would appreciate it

How to save the names and scores?

I created an object which saves one score and no name.
Maybe people would play a game where only your highest score is saved!?


How do i insert the names? I want to type them in

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #3 on: February 08, 2020, 01:25:56 PM »
That namething is optional ... if you only want to store the score you could even use a simple integer array (scores:int[10]).


Code: BlitzMax
  1. SuperStrict
  2. Framework BRL.StandardIO
  3. Import Brl.LinkedList
  4.  
  5.  
  6. Type THighscoreEntry
  7.         Field score:Long
  8.         Field name:String
  9.        
  10.         Method New(score:Long, name:String)
  11.                 self.score = score
  12.                 self.name = name
  13.         End Method
  14.  
  15.        
  16.         Method Compare:Int(other:object)
  17.                 Local otherHE:THighscoreEntry = THighscoreEntry(other)
  18.                
  19.                 If Not otherHE
  20.                         Return -1
  21.                 ElseIf score > otherHE.score
  22.                         Return -1
  23.                 ElseIf score < otherHE.score
  24.                         Return +1
  25.                 Else
  26.                         Return 0
  27.                 EndIf
  28.         End Method
  29. End Type
  30.  
  31.  
  32. Type THighscore
  33.         Field entries:TList = new TList
  34.         Field entriesLimit:int = -1
  35.         Field duplicateEntries:Int = False
  36.        
  37.        
  38.         Method New(entriesLimit:Int = -1, duplicateEntries:Int = False)
  39.                 self.entriesLimit = entriesLimit
  40.                 self.duplicateEntries = duplicateEntries
  41.         End Method
  42.        
  43.  
  44.         Method Add(entry:THighscoreEntry)
  45.                 'check if already there and remove old value if score is lower
  46.                 If not duplicateEntries
  47.                         Local oldEntry:THighscoreEntry = Get(entry.name)
  48.                         If oldEntry and oldEntry.score < entry.score
  49.                                 entries.Remove(oldEntry)
  50.                         EndIf                  
  51.                 EndIf
  52.                
  53.                 entries.AddLast(entry)
  54.  
  55.                 entries.sort()
  56.                 If entriesLimit > 0
  57.                         While entries.Count() > entriesLimit
  58.                                 entries.RemoveLast()
  59.                         Wend
  60.                 EndIf
  61.         End Method
  62.  
  63.        
  64.         Method Get:THighscoreEntry(name:String)
  65.                 For local e:THighscoreEntry = EachIn entries
  66.                         If e.name.ToLower() = name Then Return e
  67.                 Next
  68.                
  69.                 Return Null
  70.         End Method
  71.        
  72.        
  73.         'sample how iterate through the entries
  74.         Method AsText:String()
  75.                 local s:String
  76.                 For local e:THighscoreEntry = EachIn entries
  77.                         'to avoid RSet and LSet we do it that way :D
  78.                         local paddedName:String = e.name + "..............................."
  79.                         local paddedScore:String = "........" + string(e.score)
  80.                         s :+ paddedName[.. 20] + paddedScore[paddedScore.length - 8 .. ] + "~n"
  81.                 Next
  82.                 Return s
  83.         End Method
  84.        
  85.        
  86.         Method Load(filename:String)
  87.                 '...
  88.         End Method
  89.  
  90.        
  91.         Method Save(filename:String)
  92.                 '...
  93.         End Method
  94. End Type
  95.  
  96.  
  97.  
  98. 'Test
  99. local h:THighscore = new THighscore(5)
  100. h.Add( new THighscoreEntry(100, "Peter") )
  101. h.Add( new THighscoreEntry(200, "Peter") )
  102. h.Add( new THighscoreEntry(2500, "Peter") )
  103. h.Add( new THighscoreEntry(1000, "HelloWorld") )
  104. h.Add( new THighscoreEntry(2000, "Dude") )
  105. h.Add( new THighscoreEntry(3000, "Blitz") )
  106. h.Add( new THighscoreEntry(4000, "Max") )
  107. h.Add( new THighscoreEntry(5000, "Syntaxbomb") )
  108. h.Add( new THighscoreEntry(300000, "Cheater") )
  109.  
  110. print "Highscore:"
  111. print h.AsText()
  112.  


Output:
Code: [Select]
./bmk makeapp -g x64 -t gui -quick -r -x "/home/ronny/Arbeit/Programmieren/Projekte/Testcodes/highscore.bmx"
[ 80%] Processing:highscore.bmx
[ 90%] Compiling:highscore.bmx.gui.release.linux.x64.c
[100%] Linking:highscore
Executing:highscore
Highscore:
Cheater...............300000
Syntaxbomb..............5000
Max.....................4000
Blitz...................3000
Peter...................2500

bye
Ron

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #4 on: February 08, 2020, 04:05:43 PM »
Thank you a lot for doing all the coding for me!

I will try this in time.

Why did you write "..." within the load and save methods

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #5 on: February 08, 2020, 05:41:39 PM »
As I did not implement it.. "todo" ;-)

Had the kids on the lap and was almost on the go so it needed to be a bit shorter.

To save just iterate over the entries similar to the "AsText" and save it that way.

Or you could go over the top and use jconv (brucey wrote s nice tutorial for it on blitzmax.org - docs/api - brl.jconv


Bye
Ron

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #6 on: February 09, 2020, 08:14:28 AM »
Please could you just enter the code on how to save and how to load?

I do not understand at the moment.


And by the way: how do i type in my name when i got a score?

I mean: how to save my typed in names? You understand what i mean?
I want the player to be able to input his own name

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #7 on: February 09, 2020, 08:32:53 AM »
Name input is nothing I would explain here ... simplest variant would maybe some 3-letter thing, a "active letter" variable. and then you either check for each individual letter ("if Keyhit(KEY_A)" or you have something like a "activeChar" integer variable and with your cursor up/down you change this value. This value would then display A, B ... Z.

Another option is to display little buttons to click on - but I will not explain that here - other things to learn for you first.



Saving/Loading:
https://blitzmax.org/docs/en/api/brl/brl.stream/
-> WriteStream() and ReadStream() are what you could use

As said, iterate ("for ... eachin") over the entries and save each entry on a line (separate name and score with a character not allowed for the name - maybe a KEY_TAB or "::" double colon).

On loading for each line you read in the line as a string, and then "string.split(yourSpecialChar)" results in an array of 2 strings - first is the number, second the score. Then with this do the same as in my sample: add new highscore entries based on these information.


This time I do not prepare a complete working example - copy pasting does not teach you much.


PS: You do not need to send me a personal message each time you replied - I am regularly checking these forums.

bye
Ron

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #8 on: February 09, 2020, 08:39:28 AM »
Thank you again!

Well i just think that now i failed at creating a high score list.

I will go with my own solution on saving just one score: the highest without any names to put in.

I am sorry but i just don' t understand what you are explaining to me. Maybe i am not as good at programming as i thought.
Thank you anyway!!


PS: i am working on this list thingy for month now

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #9 on: February 09, 2020, 10:59:10 AM »
You better explain what you are failing at - instead of just saying you are failing.

We could try to step by step make you learn something and to remove the errors you have in your code.


PS: as said, please do not write me personal messages just to remind me to look at this thread here.

bye
Ron

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #10 on: February 09, 2020, 12:33:45 PM »
Well i do not understand how to save and load and i do not understand how to enter your name . 3 letters would be fine

I would love if you give me a full working code.
I do not want you to program my game fir me only this high score list... :(

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #11 on: February 09, 2020, 12:53:30 PM »
I won't give a whole "working code".

Handling user input can be done in various ways - and I sketched out some of them in an earlier post.
If this is "too much" then just step back and skip highscores for now and try it later, when you are a bit more experienced.


If you do not try stuff on your own here - and report where you are failing so we can help in specific areas of your code - then I will not provide further code here.


bye
Ron

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #12 on: February 09, 2020, 12:59:10 PM »
Well thanks!
I will come back to this when i am more experienced at coding.

I tried the digesteroid example but it wont save names
And it erases all other scores.

I will go on with the one highscore i programmed myself.
The gameboy game solar striker works just like that! It only shows one score. The highest

Do you think people may enjoy a game that handles scores like this?


Btw: i can not provide code here because i only have internet on my cellphone
Thank you again for your help

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #13 on: February 09, 2020, 03:42:39 PM »
@ cellphone
OK ... that is ... ok that is odd but yeah. So you read my code and type it into your computer then?
Maybe use your cellphone as wifi AP so you can connect via your computer to it.


@ highscore
Yes store one then - you can extend later to store more.


bye
Ron

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #14 on: February 09, 2020, 05:26:10 PM »
Yes i type your code in my pc.

You are a really nice person helping others!!

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal