The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.38 / 5.00 36,385 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 13,902 Viewsim almost done with a game im making,i need to know how to keep a hp level from going over the maximum,any ideas
Your hp has a value right?
So,
if hp>=(your max hp) {
hp==(your max hp)
}
simple?
At 8/27/08 07:56 AM, colintso wrote: Your hp has a value right?
So,
if hp>=(your max hp) {
hp==(your max hp)
}
simple?
Wow lets clean that up a bit so it's actually helpful and correct.
var hp:Number = 100;
var maxHP:Number = 100;
if(hp>=maxHP){
hp=maxHP;
}
remember to check that everytime you add health to the player.
At 8/27/08 10:59 AM, Cojones893 wrote:At 8/27/08 07:56 AM, colintso wrote: Your hp has a value right?Wow lets clean that up a bit so it's actually helpful and correct.
So,
if hp>=(your max hp) {
hp==(your max hp)
}
simple?
var hp:Number = 100;
var maxHP:Number = 100;
if(hp>=maxHP){
hp=maxHP;
}
remember to check that everytime you add health to the player.
I assume he won't need to declare HP and it's already in a variable.
Also, he doesn't HAVE to have a maxHP var, but you're definatly correct in saying he should
- Matt, Rustyarcade.com
At 8/27/08 11:51 AM, Rustygames wrote:At 8/27/08 10:59 AM, Cojones893 wrote:I assume he won't need to declare HP and it's already in a variable.At 8/27/08 07:56 AM, colintso wrote: Your hp has a value right?Wow lets clean that up a bit so it's actually helpful and correct.
So,
if hp>=(your max hp) {
hp==(your max hp)
}
simple?
var hp:Number = 100;
var maxHP:Number = 100;
if(hp>=maxHP){
hp=maxHP;
}
remember to check that everytime you add health to the player.
Also, he doesn't HAVE to have a maxHP var, but you're definatly correct in saying he should
Agreed. A better version of this code, though, would be using a while() loop, to avoid the one frame in which you can see the hp above the maximum that you get otherwise:
var hp:Number = 100;
var maxHP:Number = 100;
while(hp>maxHP){
hp=maxHP;
}
;D
Song of the Firefly is on Steam Greenlight and Kickstarter. Give them a look and support the project!
------------------------------
That's just not true. Just update the text field after you do that operation. I don't see how that while loop will solve anything...
- Matt, Rustyarcade.com
At 8/27/08 02:52 PM, Rustygames wrote: That's just not true. Just update the text field after you do that operation. I don't see how that while loop will solve anything...
EnterFrame works every frame. When I use that code, I get a single frame in which the health is above the maximum, which, of course, flashes and then vanishes. It looks unprofessional. The while loop runs it more than one a frame, so the number is reset before the next frame, which allows for a smoother look.
Song of the Firefly is on Steam Greenlight and Kickstarter. Give them a look and support the project!
------------------------------
Easiest way of all avoids all if statements and while loops:
currentHP = Math.min(currentHP, maxHP)
Or, to incorporate that directly into a healing routine:
currentHP = Math.min(currentHP + healAmount, maxHP);
At 8/27/08 03:20 PM, Hoeloe wrote:At 8/27/08 02:52 PM, Rustygames wrote: That's just not true. Just update the text field after you do that operation. I don't see how that while loop will solve anything...EnterFrame works every frame. When I use that code, I get a single frame in which the health is above the maximum, which, of course, flashes and then vanishes. It looks unprofessional. The while loop runs it more than one a frame, so the number is reset before the next frame, which allows for a smoother look.
I think you've completely misunderstood what the while loop does... The display is only updated every frame. So your code does exactly the same as an if...
Also, I assume you are just setting a dynamic text fields "var" property to hp, you shouldn't be doing this, just update it after all operations are done like so:
hp_txt.text = hp;
At 8/27/08 03:49 PM, Ben-Fox wrote: Easiest way of all avoids all if statements and while loops:
currentHP = Math.min(currentHP, maxHP)
Or, to incorporate that directly into a healing routine:
currentHP = Math.min(currentHP + healAmount, maxHP);
That's actually much better, use this method
- Matt, Rustyarcade.com