Reputation: 3
I've made it so I have a progress bar which is the players health starting at 100 and going down over time via a timer. When the player health progress bar gets to 0, I want a message to come up saying "You died! Game over."
Instead of doing that, it just does that when I click it as soon as the progress bar has reached 0, due to the 'Handles PlayerHealth.Click' bit. But what do I change the PlayerHealth.Click to to make it so the message box comes up when the progress bar just hits 0, without having to click it?
I can't find the right thing in the intellisense list. Or is there a better method?
Here's the piece of code in question :
Private Sub AttackButton_Click(sender As System.Object, e As System.EventArgs) Handles AttackButton.Click
PlayerHealthTimer.Start()
EnemyHealth.Increment(-2)
End Sub
Private Sub PlayerHealthTimer_Tick(sender As System.Object, e As System.EventArgs) Handles PlayerHealthTimer.Tick
PlayerHealth.Increment(-2)
End Sub
Private Sub PlayerHealth_Value(sender As System.Object, e As System.EventArgs) Handles PlayerHealth.Click
If PlayerHealth.Value = 0 Then
MsgBox("You died! Game over.")
End If
End Sub
Ignore the middle sub. Thank you!
Upvotes: 0
Views: 1030
Reputation: 706
you can just use condition like
if PlayerHealth.value<=0 then
'place a message box or other way to show info message
end if
Upvotes: 1
Reputation: 5408
It fires on click because you have the MessageBox in the Sub that is handling the click method.
You may actually want to use the middle sub you said to ignore :). That one handles the logic on each tick.
Private Sub PlayerHealthTimer_Tick(sender As System.Object, e As System.EventArgs) Handles PlayerHealthTimer.Tick
PlayerHealth.Increment(-2)
if PlayerHealth.Value = 0 Then
MsgBox("You died! Game Over.")
''Then make sure to stop the timer
PlayerHealthTimer.Stop()
End If
End Sub
Upvotes: 2