I am integrating a local highscore board into my simple game. The code is based on this solution
But I am using DBUtils ExecuteHTML to display the high score records. The records are saved and read properly while the app is running. But once I exit the app and restart it, the previous records were no longer in the database.
Some of my code:
What am I doing wrong? Thanks in advance for the help.
But I am using DBUtils ExecuteHTML to display the high score records. The records are saved and read properly while the app is running. But once I exit the app and restart it, the previous records were no longer in the database.
Some of my code:
B4X:
Sub Process_Globals
Dim sqlScore As SQL
Dim DB As String : DB = "hscore.jpg"
End Sub
Sub Globals
Dim btnSave As Button
Dim edtName As EditText
Dim varName As String
Dim varScore As Int
Dim varMode As String
Dim webScore As WebView
Dim lblScore As Label
Dim lblDifficulty As Label
Dim pnlScore As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Main.PhoneOrientation.SetScreenOrientation(1)
If FirstTime Then
DBUtils.CopyDBFromAssets(DB)
sqlScore.Initialize(File.DirDefaultExternal, DB, True)
End If
Activity.LoadLayout("highscoretable")
If finalScore.enterScore = True Then
pnlScore.Visible = True
pnlScore.Width = 100%x
pnlScore.Top = 0
Select gameLevel.Mode
Case "1"
varMode = "Easy"
Case "2"
varMode = "Medium"
Case "3"
varMode = "Hard"
End Select
lblDifficulty.Top = 0
lblDifficulty.Width = 100%x
lblDifficulty.Text = "Difficulty: " & varMode
lblScore.Top = lblDifficulty.Top + lblDifficulty.Height + 2dip
lblScore.Width = 100%x
lblScore.Text = "Your score: " & game.totalPercent & "%"
edtName.Top = lblScore.Top + lblScore.Height + 2dip
edtName.Width = 100%x - 4dip - btnSave.Width
btnSave.Top = edtName.Top
btnSave.Left = edtName.Width + 2dip
End If
resizeWebView
End Sub
Sub resizeWebView
If finalScore.enterScore = False Then
webScore.Top = 0
webScore.Left = 0
webScore.Width = 100%x
webScore.Height = 100%y
Else
webScore.Top = pnlScore.Height + 2dip
webScore.Left = 0
webScore.Width = 100%x
webScore.Height = 100%y - webScore.Top
End If
loadScore
End Sub
Sub inputsControl() As Int
If edtName.Text.Length = 0 Then
edtName.Text = "---"
End If
finalScore.enterScore = False
pnlScore.Visible = False
resizeWebView
Return 0
End Sub
Sub btnSave_Click
Dim ctrl As Int
ctrl = inputsControl
If ctrl = 0 Then
varName = edtName.Text
varScore = game.totalPercent
saveScore
Else
Return
End If
End Sub
Sub saveScore
sqlScore.ExecNonQuery("INSERT INTO scores (Name, Score, Difficulty) VALUES("& "'"&varName&"'" &","&varScore&", "& "'"&varMode&"'" &")")
loadScore
End Sub
Sub loadScore
Dim scoreDat As String
scoreDat = DBUtils.ExecuteHtml(sqlScore, "SELECT * FROM scores ORDER BY Score DESC", Null, 10, False)
webScore.LoadHtml(scoreDat)
End Sub
What am I doing wrong? Thanks in advance for the help.