If ProgressBar2.Value = 0 Then
MsgBox("Black Player Wins!")
Close()
End If
If ProgressBar1.Value = 0 Then
MsgBox("White Player Wins!")
Close()
End If
Progress Bar opens Message Box?
Page 1 of 111 Replies - 766 Views - Last Post: 08 October 2012 - 06:50 AM
#1
Progress Bar opens Message Box?
Posted 03 October 2012 - 07:32 AM
So, I'm making a fighting game. my hp bars, when reach 0, are supposed to open a msgbox that says player1 wins or player2 wins.
Replies To: Progress Bar opens Message Box?
#2
Re: Progress Bar opens Message Box?
Posted 03 October 2012 - 07:56 AM
Kudos? I think you forgot the question.
#3
Re: Progress Bar opens Message Box?
Posted 03 October 2012 - 07:58 AM
ok, so whats your question? you need to provide us with a specific question, what you've done to try to solve the question, errors you've received and relevant code snippets. With out this information we really can't help you.
This post has been edited by rgfirefly24: 03 October 2012 - 07:58 AM
#4
Re: Progress Bar opens Message Box?
Posted 04 October 2012 - 05:15 AM
Okey. If you don't want to add a Timer, I can't really help you. But, you add a timer with this code:
And when you are launching the game (starting it):
Not 100% sure this will work, but its worth a try :-)
If ProgressBar1.Value = "0" Then
MsgBox("Player1 wins")
Timer1.Enabled = False
ElseIf ProgressBar2.Value = "0" Then
MsgBox("Player2 wins")
Timer1.Enabled = False
End If
And when you are launching the game (starting it):
Timer1.Enabled = True
Not 100% sure this will work, but its worth a try :-)
#5
Re: Progress Bar opens Message Box?
Posted 04 October 2012 - 05:42 AM
There is no reason to use timer. Again, until the OP actually poses a question there is nothing we can do.
This post has been edited by rgfirefly24: 04 October 2012 - 09:26 AM
#6
Re: Progress Bar opens Message Box?
Posted 04 October 2012 - 06:08 AM
I'm thinking the OP is implying the question, "Why doesn't this work" because he is assuming the either ProgressBar1.Value = 0 or ProgressBar2.Value = 0 and therefore should produce a MessageBox and it doesn't.
TheVoliand, Place a breakpoint in your code where you think a condition should fire of this check and step through the code and look at the values of both progressbars. If one of them = 0 then step on through to see why it's not reaching this block of code and if it is reaching this block of code, why did the value change from 0.
The code you have above is error free and therefore means that you have a logic problem (this could be that you're not processing that code or that the values are not what you expect when it reaches this code)
That's pretty much all we can give without more input from you.
TheVoliand, Place a breakpoint in your code where you think a condition should fire of this check and step through the code and look at the values of both progressbars. If one of them = 0 then step on through to see why it's not reaching this block of code and if it is reaching this block of code, why did the value change from 0.
The code you have above is error free and therefore means that you have a logic problem (this could be that you're not processing that code or that the values are not what you expect when it reaches this code)
That's pretty much all we can give without more input from you.
This post has been edited by CharlieMay: 04 October 2012 - 06:09 AM
#7
Re: Progress Bar opens Message Box?
Posted 04 October 2012 - 06:44 AM
Im not sure if VB.net has unsigned integers but if it does you could make your variables unsigned int so that no matter the damage your player takes the value will be no less that 0.
#8
Re: Progress Bar opens Message Box?
Posted 08 October 2012 - 05:35 AM
sorry the problem was that when i tried to debug it i could get the hp bar to 0 and then an error occurs where it says you -20 is not a valid value. i can get it to open the msgbox, but after that it pretty much crashes
#9
Re: Progress Bar opens Message Box?
Posted 08 October 2012 - 05:57 AM
By default, ProgressBar has set minimum value to 0, and maximum to 100. You can set them different, but usually, that is not needed, because they are used as representation of percentage (0 to 100%).
When you subtract fighters' damage to -20, the exception is thrown. This means, you'd probably want to prevent the damage to be less than 0. Unless you want your worrier to be more dead than dead
When you subtract fighters' damage to -20, the exception is thrown. This means, you'd probably want to prevent the damage to be less than 0. Unless you want your worrier to be more dead than dead
This post has been edited by lucky3: 08 October 2012 - 06:01 AM
#10
Re: Progress Bar opens Message Box?
Posted 08 October 2012 - 06:06 AM
TheVoliand
Did you check to see if the damage takes the value below 0 prior to setting the new value to the progressbar?
ie:
Did you check to see if the damage takes the value below 0 prior to setting the new value to the progressbar?
ie:
Damage = 20 If ProgressBar1.Value - Damage =< 0 Then 'Meaning this will cause an exception if you try to set it ProgressBar1.Value = 0 'Since it would take it < 0 and cause an exception, force it to 0 'Do Death Routine Else ProgressBar1.Value -= Damage 'Otherwise, subtract damage and wait for more damage End If
#11
Re: Progress Bar opens Message Box?
Posted 08 October 2012 - 06:15 AM
charliemay, that makes it so that they both die instantly
Figured it out, charliemay what was wrong when i attempted your code was the else was put in a timer, which meant it would just hit -20 infinitly, but the <= was what i needed thanks!
Figured it out, charliemay what was wrong when i attempted your code was the else was put in a timer, which meant it would just hit -20 infinitly, but the <= was what i needed thanks!
#12
Re: Progress Bar opens Message Box?
Posted 08 October 2012 - 06:50 AM
OK , that was a demonstration. You would pass your damage to the routine. Where I set 20 was to demonstrate subtracting a variable. For example, if you have a progress bar with a total of 61 it would take 4 hits to kill because each hit is 20 but without the check, the 4th hit would cause -19 which would throw an exception so the check is put in place to say if it WOULD go below 0 make it 0. Thus, no exception thrown.
Part of this is you're taking what people show you and trying to make it work verbatim. You need to understand that the only thing I'm trying to show you is how to subtract from a ProgressBar .Value without causing an ArgumentException. What those values are and how you subtract them is part of your code logic.
Part of this is you're taking what people show you and trying to make it work verbatim. You need to understand that the only thing I'm trying to show you is how to subtract from a ProgressBar .Value without causing an ArgumentException. What those values are and how you subtract them is part of your code logic.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote










|