February 19, 2020, 02:21:56 AM

Author Topic: High Score Explanation  (Read 421 times)

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #15 on: February 09, 2020, 06:05:57 PM »
Is your data rate on the phone limited? if not you might really want to expose the cell phone data connection as Wireless Lan Access Point or you could use tethering (connect computer to the phone). Would make life easier.


Nonetheless: it is really helping if you have specific pieces of code which fail - so we could tackle that instead of guessing by reading yours or my prosa texts :D


bye
Ron

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #16 on: February 10, 2020, 10:03:02 AM »
Yes my data rate is limited

Maybe i could post a screenshot of the code?

I attached a bmx to this post containing the essential parts of my code

Gameover and Score are variables i declared at the beginning of my program. You would need them to be entered in this part of code

You will also need to create THighScores:
Global ScoresX:THighScores=THighScores.Load("hi.dat")

And:
Global MenuScene:MainMenuScene=New MainMenuScene

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #17 on: February 10, 2020, 03:42:32 PM »
If you prefer you can just talk in German to me but of course this would be problematic for other users :D

Code: [Select]
Method IsHighScore:Int(Score:Int)''''''''''''''''''''''''''''''''evntl. zu Scor umbenennen damit er ieder Score annimmt

I do not understand why you would want to rename "Score" to "Score" ?


Aside of that: I have this .bmx now - what to do with it, and for what reason did you upload these pictures too?


@ data rate
Can you load data from your computer to the phone ? Eg. shared wifi connection/LAN - or via USB connection (as if you want to move pictures from phone to computer) - would save the hassle of typing stuff in.

/alt:
Du kannst doch einfach Dein Handy ins gleiche WLan wie den Computer einklinken - oder das Handy mit einem USB-Kabel verbinden (und dann im Explorer/Dateimanager entsprechend Dateien kopieren). Alles ein wenig umstaendlich, aber besser als hier Megabytes an Fotos hochzuladen.


bye
Ron

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #18 on: February 10, 2020, 04:10:41 PM »
Hallo Ron!
Das ist ja cool, dass du deutsch bist :)

Die .bmx hab ich geposted, da ich hoffe, dass du
Die fehler beheben kannst oder mir dabei hilfst.

Das mit den Bildern war vlt keine gute idee

Ich kann nix verbinden, da ich ├╝berhaupt kein wlan habe!
Ich habe nur internet am smartphone...

Hast du die .bmx mal probiert um zu sehen was sie falsch macht? Irgendwo da im code liegt der Fehler und
Ich hatte gehofft, du k├Ânntest mir dabei helfen ihn zu beheben oder direkt den code zu korrigieren...

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2230
  • elgol developer
Re: High Score Explanation
« Reply #19 on: February 10, 2020, 04:13:01 PM »
Please speak English on this forum, or use private message for non-English conversations.
Windows 10, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
MacOS Catalina, 64-bit, 8Gb RAM, CPU Intel i5, 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB.
Linux Mint 19.2, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
C64, Raspberry pi 3

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #20 on: February 10, 2020, 05:03:19 PM »
Ok, sorry.

Can't anybody help me with the code?

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2230
  • elgol developer
Re: High Score Explanation
« Reply #21 on: February 10, 2020, 05:25:02 PM »
Sorry I don't use BMX.
Windows 10, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
MacOS Catalina, 64-bit, 8Gb RAM, CPU Intel i5, 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB.
Linux Mint 19.2, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
C64, Raspberry pi 3

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #22 on: February 10, 2020, 05:43:25 PM »
Please speak English on this forum, or use private message for non-English conversations.

As nobody else was joining this thread  I felt it were ok to write certain stuff (additionally) in German to make things more clear. For you as native English speaker there is no language barrier but for others it often means to (sometimes) use wrong words leading to potential misinterpretation.

It was not my intention to switch to a (written-in-)German-only-thread, I just offered that he can write to me in German too.


@chessish
I will hopefully be able to look at it later this evening.


bye
Ron

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #23 on: February 10, 2020, 05:56:00 PM »
Quick glance:

Code: [Select]
Compile Error: Identifier 'Score' not found.
[/highscores.bmx;120;0]

I reformatted your MainMenuScene type a bit - to ease grasping what happens there:
Code: BlitzMax
  1. Type MainMenuScene
  2.                 Field EnteredText:String
  3.                 Field LastHighScore:Int
  4.        
  5.                 Method FinishScoreEntry()
  6.                         'Scores.Add(Self.LastHighScore, Self.EnteredText)
  7.  
  8.                         ' Add this to the high scores..
  9.                         Self.LastHighScore = Score
  10.                         Self.EnteredText = ""
  11.                        
  12.                         'Scores.Save("hi.dat")
  13.                 End Method
  14.                
  15.                
  16.                 Method UpdateState()
  17. 'Select Self.Viewing
  18. 'Case VIEW_ENTERHIGH
  19.                 'Rem
  20.                 ' Check for alpha keys.
  21.                 If gameover = 1
  22.                         For Local Count:Int = KEY_A To KEY_Z
  23.                                 If KeyHit(Count) Then Self.EnteredText = Self.EnteredText + Chr(Count)
  24.                         Next
  25.  
  26.                         ' Check For number key hits
  27.                         For Local Count2:Int = KEY_0 To KEY_9
  28.                                 If KeyHit(Count2) Then Self.EnteredText = Self.EnteredText + Chr(Count2)
  29.                         Next
  30.  
  31.                         ' Special case, check for space bar
  32.                         If KeyHit(KEY_SPACE)
  33.                                 Self.EnteredText = Self.EnteredText + " "
  34.                         EndIf
  35.                
  36.                         ' Remove a character when user hits backspace.
  37.                         If KeyHit(KEY_BACKSPACE)
  38.                                 If Len(Self.EnteredText) > 0
  39.                                         Self.EnteredText = Mid(Self.EnteredText,0,Len(Self.EnteredText))
  40.                                 EndIf
  41.                         EndIf
  42.  
  43.                         ' If 5 characters are entered, end high score entry.
  44.                         If Len(Self.EnteredText) = 5 Then Self.FinishScoreEntry()
  45.        
  46.                         ScoresX.Add(Self.LastHighScore, Self.EnteredText)
  47.                         ScoresX.Save("hi.dat")
  48.  
  49.                         If KeyHit(KEY_ENTER)
  50.                                 Self.FinishScoreEntry()
  51.                                 ScoresX.Save("hi.dat")
  52.                         EndIf
  53.                 EndIf
  54.  
  55.                 'EndRem
  56.  
  57.                 'End Select
  58.                 If gameover = 1
  59.                         'ScoresX.Add(Self.LastHighScore, Self.EnteredText)
  60.                 EndIf
  61.         End Method
  62. End Type
  63.  

so if "gameover = 1" ... what happens the WHOLE time?
- Keys are checked and the "EnteredText" is modified (chars added, deleted...)
- if "EnteredText" is 5 chars then call "FinishScoreEntry()"
- add "LastHighScore" to a file
- ...

So each time you call "UpdateState" you would check for a new pressed/hit key - but also EACH time save the "LastHighScore" to a file.

I assume you should only do that on "KEY_ENTER" (so "confirming your name").


back to "self.LastHighScore = Score" - you need a new "Field Score:Int" in your "MainMenuScene" (or somewhere else). This is the value you populate with your current score - change it if the player earns points and reset if needed (eg new game).

In "FinishScoreEntry()" you add it to an instance of "THighScores" ... so have a "field highscores:THighScores = new THighScores" (or so) there. Then "highscores.Add(score, name)" will add it. Keep the 'EnteredText = ""' reset in there. No need for "LastHighScore".

Code: BlitzMax
  1.                         ScoresX.Add(Self.LastHighScore, Self.EnteredText)
  2.                         ScoresX.Save("hi.dat")
  3.  
can be removed from "UpdateState"), same for 'ScoresX.Save("hi.dat")' - you will just do the add and save within the "FinishScoreEntry()"


bye
Ron

 

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #24 on: February 10, 2020, 06:02:28 PM »
This at least compiles - I restructured the MainScene type a bit.

Code: BlitzMax
  1. Type THighScores
  2.  
  3.         Const SCORE_COUNT = 10
  4.         Field Scores:Int[SCORE_COUNT]
  5.         Field Names:String[SCORE_COUNT]
  6.  
  7.         Method Render(X:Int, Y:Int)
  8.                 For Local Count:Int = 0 To SCORE_COUNT - 1
  9.                         DrawText(Self.Names[Count], X,Y + (Count * 20))
  10.                 Next
  11.  
  12.                 For Local Count2:Int = 0 To SCORE_COUNT - 1
  13.                         DrawText(Self.Scores[Count2], X + 200,Y + (Count2 * 20))
  14.                 Next
  15.         End Method
  16.  
  17.         Method IsHighScore:Int(Score:Int)''''''''''''''''''''''''''''''''evntl. zu Scor umbenennen damit er ieder Score annimmt
  18.                 For Local Count:Int = 0 To SCORE_COUNT - 1
  19.                         If Score > Self.Scores[Count] Then
  20.                                 Return True
  21.                         EndIf
  22.                 Next
  23.                 Return False
  24.         End Method
  25.        
  26.         Method Add(Score:Int,Name:String)
  27.                 ' Find out where we should put the score..
  28.                 Local PlaceAt:Int = SCORE_COUNT - 1
  29.                 For Local Count:Int = SCORE_COUNT - 1 To 0 Step -1
  30.                         If Score > Self.Scores[Count] Then
  31.                                 PlaceAt = Count
  32.                         EndIf
  33.                 Next
  34.  
  35.                 ' Shuffle them all down..
  36.                 For Local Shuffle:Int = SCORE_COUNT - 2 To PlaceAt Step -1
  37.                         Self.Scores[Shuffle + 1] = Self.Scores[Shuffle]
  38.                         Self.Names[Shuffle + 1] = Self.Names[Shuffle]
  39.                 Next
  40.  
  41.                 Self.Scores[PlaceAt] = Score
  42.                 Self.Names[PlaceAt] = Name
  43.         End Method
  44.  
  45.         Method Save(File:String)
  46.                 Local Out:TStream = OpenStream(File,False,True)
  47.                 If Out <> Null
  48.                         For Local Count:Int = 0 To SCORE_COUNT - 1
  49.                                 WriteInt(Out,Self.Scores[Count])
  50.                                 WriteLine(Out,Self.Names[Count])
  51.                         Next
  52.                         CloseStream(Out)
  53.                 EndIf
  54.         End Method
  55.  
  56.         Function Load:THighScores(File:String)
  57.                 Local In:TStream = OpenStream(File,True,False)
  58.                 Local Out:THighScores = New THighScores
  59.                 If In = Null
  60.                         ' Fill it full of high scores..
  61.                         Out.Names[0] = "Loki"
  62.                         Out.Names[1] = "Booty"
  63.                         Out.Names[2] = "Rix"
  64.                         Out.Names[3] = "Jamez"
  65.                         Out.Names[4] = "Pies"
  66.                         Out.Names[5] = "Bobny"
  67.                         Out.Names[6] = "Berty"
  68.                         Out.Names[7] = "Billy"
  69.                         Out.Names[8] = "Bonny"
  70.                         Out.Names[9] = "Boxer"
  71.  
  72.                         Out.Scores[0] = 100000
  73.                         Out.Scores[1] = 80000
  74.                         Out.Scores[2] = 50000
  75.                         Out.Scores[3] = 40000
  76.                         Out.Scores[4] = 30000
  77.                         Out.Scores[5] = 20000
  78.                         Out.Scores[6] = 10000
  79.                         Out.Scores[7] = 5000
  80.                         Out.Scores[8] = 4000
  81.                         Out.Scores[9] = 1000
  82.                 Else
  83.                         For Local Count:Int = 0 To SCORE_COUNT - 1
  84.                                 Out.Scores[Count] = ReadInt(In)
  85.                                 Out.Names[Count] = ReadLine(In)
  86.                         Next
  87.                         CloseStream(In)
  88.                 EndIf
  89.                 Return Out
  90.         End Function
  91.  
  92. End Type
  93.  
  94.  
  95. Rem
  96. Type T2DDynamicGameScene
  97.  
  98.         Field TerminateMainLoop:Int = False    
  99.  
  100.         Method Update() Abstract
  101.         Method Render() Abstract
  102.         Method Start() Abstract
  103.         Method Finish() Abstract
  104.  
  105.  
  106. End Type
  107. EndRem
  108.  
  109. Type MainMenuScene
  110.         Field EnteredText:String
  111.         Field CurrentScore:Int
  112.         Field Scores:THighScores = new THighScores
  113.         Field gameover:Int = 0
  114.        
  115.         Method FinishScoreEntry()
  116.                 'add and save score
  117.                 Scores.Add(Self.CurrentScore, Self.EnteredText)
  118.                 Scores.Save("hi.dat")
  119.  
  120.                 ' Reset entered text for next add
  121.                 Self.EnteredText = ""
  122.         End Method
  123.                
  124.                
  125.         Method UpdateState()
  126.                 'Select Self.Viewing
  127.                         'Case VIEW_ENTERHIGH
  128.                                 ' Check for alpha keys.
  129.                                 If gameover = 1
  130.                                         ' only add new chars if we are below 5 chars
  131.                                         If Len(Self.EnteredText) < 5
  132.                                                 For Local Count:Int = KEY_A To KEY_Z
  133.                                                         If KeyHit(Count) Then Self.EnteredText :+ Chr(Count)
  134.                                                         If Len(self.EnteredText) >= 5 then exit
  135.                                                 Next
  136.                                         EndIf
  137.  
  138.                                         If Len(Self.EnteredText) < 5
  139.                                                 ' Check For number key hits
  140.                                                 For Local Count2:Int = KEY_0 To KEY_9
  141.                                                         If KeyHit(Count2) Then Self.EnteredText :+ Chr(Count2)
  142.                                                         If Len(self.EnteredText) >= 5 then exit
  143.                                                 Next
  144.                                         EndIf
  145.  
  146.                                         ' Special case, check for space bar
  147.                                         If Len(Self.EnteredText) < 5
  148.                                                 If KeyHit(KEY_SPACE)
  149.                                                         Self.EnteredText :+ " "
  150.                                                 EndIf
  151.                                         EndIf
  152.  
  153.                                         ' Remove a character when user hits backspace.
  154.                                         If KeyHit(KEY_BACKSPACE) And Len(Self.EnteredText) > 0
  155.                                                 Self.EnteredText = Left(Self.EnteredText, Len(Self.EnteredText)-1)
  156.                                                 'other way via slicing newString = otherString[(start) .. (length)] - also works for arrays
  157.                                                 'Self.EnteredText = Self.EnteredText[.. Len(Self.EnteredText)-1]
  158.                                         EndIf
  159.                
  160.                                         'user confirmed name
  161.                                         If KeyHit(KEY_ENTER)
  162.                                                 Self.FinishScoreEntry()
  163.                                         EndIf
  164.                                 EndIf
  165.                 'End Select
  166.         End Method
  167. End Type
  168.  
  169.  

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #25 on: February 10, 2020, 06:04:04 PM »
Could you please upload this whole code you did as a .bmx?

Thanks a lot in advance for doing all the hard work for me!!!

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #26 on: February 10, 2020, 06:06:51 PM »
Copy paste it into a new file ?
Hmm... odd wishes sometimes :D

Appended as file too .

Offline chessish

  • Jr. Member
  • **
  • Posts: 33
Re: High Score Explanation
« Reply #27 on: February 10, 2020, 06:14:11 PM »
Ah that is what i needed!
I will try this tomorrow!

Just how old are you? I am 31.
I am surprised that a person is helping others
Without any thought of reward!
If this code works i will luv you forever xD

Coool thing to meet another german.

Where did you learn to code so well??

Many greetings to you!

Bye chris

Offline Derron

  • Hero Member
  • *****
  • Posts: 2716
Re: High Score Explanation
« Reply #28 on: February 10, 2020, 07:33:28 PM »
If you help others chances are high that others help you too.

Born in 1981 and most coding knowledge is based on self-teaching ("learning by doing").


Bye
Ron

Offline Matty

  • Hero Member
  • *****
  • Posts: 823
    • MattiesGames
Re: High Score Explanation
« Reply #29 on: February 10, 2020, 11:55:17 PM »
My two cents...

Most people will help another in genuine need if they have the resources to do so moderately easily.

It's when the needy person is just playing games with the helper that help available can become scarce.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal