Android Tutorial Local High Score Leaderboard

Penko

Active Member
Licensed User
Longtime User
Do you want us to report about phone display issues?

On my HTC Desire, I am seeing up to the "ma" syllable in "Information". The Submit button is visible in Portrait mode but it's just 2-3dip from the activity frame(is it intended to be there)?

Landscape is better when it comes to the first EditText View(The second is cut in half) but the Submit button is totally missing.

It's 04:30 AM here, I don't want to go in details for now but the HighScoreSorting algorithm seems complex to me and probably can be made easier. I see too many if/else statements. Maybe there is a more dynamic way to fulfill this task. Will try to check back tomorrow.
 

PharCyDeD

Active Member
Licensed User
Longtime User
It is just an example and not intended to be used as is on any device. Run it on an emulator with 1280x800x160 layout variant. If you can simplify the code then by all means post it :)
 

PharCyDeD

Active Member
Licensed User
Longtime User
Timo, I am curious about your solution. When I try to add another DB like:

B4X:
   Dim SQL2 As SQL
   Dim DB2target As String    : DB2target= File.DirInternal
   Dim DB2 As String       : DB2 = "normalhiscore.db"


B4X:
If FirstTime Then
      installDB
      SQL1.Initialize(DBtarget, DB, True)
      SQL2.Initialize(DB2target, DB2, True)
      
   End If

It stops me in installDB saying normalhiscore.db does not exist (FileNotFoundException). I thought that if it did not exist it would create it? Am I missing something?
 

timo

Active Member
Licensed User
Longtime User
Did you externally ceate an empty 'normalhiscore.db' and add it to your project 'Files' folder? (DirAssets)
And then you have to modify the sub 'installDB', because if you let it as it is it doesn't copy DB2, but only DB.
You can put in it arguments to receive, for example, and call it for DB2 too.
(You don't have to change 'DBtarget')
B4X:
.....
If FirstTime Then
installDB(DB)
installDB(DB2)
SQL1.Initialize(DBtarget, DB, True)
SQL2.Initialize(DBtarget, DB2, True)

End If

.....MODIFIED:
Sub installDB (dataBase As String)
If File.Exists(DBtarget, dataBase) = False Then
   File.Copy(File.DirAssets, dataBase, DBtarget, dataBase)
End If
End Sub
 

Attachments

  • db.jpg
    db.jpg
    46.3 KB · Views: 363
Last edited:

PharCyDeD

Active Member
Licensed User
Longtime User
I was under the impression the database file was being generated for some reason. Thanks for your response gonna check it out now :)
 

PharCyDeD

Active Member
Licensed User
Longtime User
Hmm, now I am just trying to implement your solution into my app "as is" with no changes. I copied the db file from your project and put it in my folder, but I get an "SQLiteException: no such table: scores:" error when running.

It is highlighting in load:

B4X:
Cursor = SQL1.ExecQuery("SELECT * FROM scores ORDER BY score DESC LIMIT 5")



***EDIT***

It appears that for whatever reason I had to open the db file in SQLite Browser and rename the table...then rename it in the code and all worked fine. Any idea of why this made it work?
 
Last edited:

PharCyDeD

Active Member
Licensed User
Longtime User
Ha! Thanks again for the replies and the obviously superior solution to a local high score leaderboard. My version could get insanely confusing if it was say the Top 20 lol! I really hate problems like the one I ran into. First, I was like oooooooooooh I gotta create have a copy of the DB file for the program to use...no problem. Then I use the same DB file and same code and my app complains about it. At least renaming the table worked though!
 

timo

Active Member
Licensed User
Longtime User
You're welcome. In the past I also was a 'glass climber' because I hated databases. SQLite is stable, simple, light and easy to manage; just don't use it now to ask what time is it:cool:
 

HimeAnator

Member
Licensed User
Longtime User
I hate to revive such an old post, however I'm starting to dip into developing games and this is just what I'm looking for. I am wondering though if it is possible to figure out whether the score is in the top 10 or not (I did change the code to display 10 scores). For example, if the users score is in the top 10 then I'm trying to display a message that says "New High Score!" or if the users score is the highest/number 1 score then I'm trying to display a message that would then say "New Top Score!". Could someone please point me in the direction in order to accomplish this? Not sure if this will make a huge difference but I also separated the entry of the scores and list display of the scores into separate activities. So the high score list is its own activity that the user will have to open in order to see the scores list and the scores them self are entered at a game over type activity screen that I've setup. So I'm trying to do the calculations at the game over screen and then display the appropriate message depending on the score and its position in the list. Any help with this would be much appreciated!
 
Top