Hi Guys,
I have a couple of problems I need help with, The first is the FirstTime run, I setup an if loop in the Activity_Create on the Main Activity to setup the databases used for scoring and such like, and it has an IF loop to detect if the files exist, but it doesn't work, I also tried the "If FirstTime Then" but that doesn't work either, it runs everytime the app is launched, code attached below :
Also I how can I set a maximum row count on the SQL database, and have any new high scores replace the lower scores? I only need 10 rows to keep the top 10 high scores
Thanks,
Andrew Montgomery-Fox
Edit: ZIP of all the code: http://amfox.eu:8080/GameSourceCode.zip got an error saying it was too big for the server so had to upload it to my server
I have a couple of problems I need help with, The first is the FirstTime run, I setup an if loop in the Activity_Create on the Main Activity to setup the databases used for scoring and such like, and it has an IF loop to detect if the files exist, but it doesn't work, I also tried the "If FirstTime Then" but that doesn't work either, it runs everytime the app is launched, code attached below :
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("game_menu")
If File.Exists(File.DirDefaultExternal, "score.db") = False Then
SQL1.Initialize(File.DirDefaultExternal, "scores.db", True)
SQL1.ExecNonQuery("DROP TABLE IF EXISTS highscore")
SQL1.ExecNonQuery("DROP TABLE IF EXISTS gamesplayed")
SQL1.ExecNonQuery("DROP TABLE IF EXISTS playername")
SQL1.ExecNonQuery("CREATE TABLE highscore (name TEXT, score INTEGER)")
SQL1.ExecNonQuery("CREATE TABLE gamesplayed (number INTEGER)")
SQL1.ExecNonQuery("CREATE TABLE playername (name TEXT)")
SQL1.ExecNonQuery2("INSERT INTO highscore VALUES(?, ?)", Array As Object ("Default", 16))
SQL1.ExecNonQuery2("INSERT INTO highscore VALUES(?, ?)", Array As Object ("Andrew", 3))
SQL1.ExecNonQuery2("INSERT INTO highscore VALUES(?, ?)", Array As Object ("Default", 0))
SQL1.ExecNonQuery2("INSERT INTO highscore VALUES(?, ?)", Array As Object ("Default", 2))
SQL1.ExecNonQuery2("INSERT INTO highscore VALUES(?, ?)", Array As Object ("Andrew", 10))
Log("Number of rows = " & SQL1.ExecQuerySingleResult("SELECT count(*) FROM highscore"))
Log("Number of rows = " & SQL1.ExecQuerySingleResult("SELECT count(*) FROM gamesplayed"))
InputName.Input = ""
InputName.Hint = "Enter Your Name"
InputName.HintColor = Colors.Cyan
playerName = DialogResponse.CANCEL
playerName = InputName.Show("Enter Your Name", "Enter Your Name", "Okay", "Cancel", "Mehbe", Null)
ToastMessageShow("Name Set! Click on your name to change it!", False)
SQL1.ExecNonQuery2("INSERT INTO playername VALUES(?)", Array As Object(playerName))
ToastMessageShow("Creating files on first run", True)
Else If File.Exists(File.DirDefaultExternal, "score.db") = True Then
ToastMessageShow("Welcome back!", False)
End If
End Sub
Also I how can I set a maximum row count on the SQL database, and have any new high scores replace the lower scores? I only need 10 rows to keep the top 10 high scores
Thanks,
Andrew Montgomery-Fox
Edit: ZIP of all the code: http://amfox.eu:8080/GameSourceCode.zip got an error saying it was too big for the server so had to upload it to my server
Last edited: