I'm making a space invaders game in vb.net however for my high score system it doesn't seem to be working correctly. Whenever I try to get a lower score than my current high score, the input box for when I actually do get a higher score than my current high score still pops up
Best
design name is the label responsible for showing who has the best high score
If Val(Lives.Text) = 0 Then`your text`
MsgBox("You Lose!")
If Val(score.Text) > Val(Highscore.Text) Then
Highscore.Text = score.Text
Highscore.Text = "high Score: " & Highscore.Text
Best.Text = InputBox("Enter your name")
Best.Text = "best Player: " & Best.Text
filenum = FreeFile()
FileOpen(filenum, "score.txt", OpenMode.Output)
PrintLine(filenum, Best.Text)
PrintLine(filenum, Highscore.Text)
FileClose(filenum)
Close()
Else
Close()
End If
End If
I tried switching around the if
statements but nothing happened
CodePudding user response:
If Val(Lives.Text) = 0 Then
MsgBox("You Lose!")
If Val(score.Text) > Val(Highscore.Text) Then
Highscore.Text = score.Text
Highscore.Text = "high Score: " & Highscore.Text
Best.Text = InputBox("Enter your name")
Best.Text = "best Player: " & Best.Text
filenum = FreeFile()
FileOpen(filenum, "score.txt", OpenMode.Output)
PrintLine(filenum, Best.Text)
PrintLine(filenum, Highscore.Text)
FileClose(filenum)
End If
Close()
End If
CodePudding user response:
You should keep your score values separatet from text. if you say Val(Highscore.text) you will get zero if the Highscore.text is "High score: 12345"