The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 5:40 am

Forum rules


IMPORTANT

This Forum is for Flash related questions ONLY! Do not ask questions about spriting, Game Maker, Photoshop, or anything else not related to Flash.



 [ 9 posts ] 
[Request] Health Bar Help 
Author Message
User avatar

Joined: Tue Oct 28, 2008 1:37 pm
Posts: 300
this is how i make my health bar decrease i want to know how to make my character go to the dead animation when the x scale is 0 and the health bar unload
Code:
onClipEvent(enterFrame){
  if(hitTest(_root.bad))(
    _root.healthBar._xscale-=1
  )
}

anyone

_________________
Image
super smash bros blits(working title)-1% done
new flash game


Mon May 04, 2009 9:32 am
User avatar

Joined: Wed Apr 29, 2009 11:28 pm
Posts: 323
Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
Code:
onClipEvent(enterFrame){
if([b]this.[/b]hitTest(_root.bad))(
_root.healthBar._xscale = [b]_root.healthBar._xscale[/b] - 1[b];[/b]
)
}


Changes put in bold.

Try using a health variable, and syncing that to the bar, not changing the bar's value itself.

_root.healthBar._xscale = CurrentHealth / MaxHealth * 100;

_________________
Image

Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper.

READ THIS: http://ipgd.freehostia.com/copypasta.html


Mon May 04, 2009 9:47 am
User avatar

Joined: Tue Oct 28, 2008 1:37 pm
Posts: 300
im a bit confused your code didn't work so i had to edit it but it still dosnt work what exactly will the changes what you did do
Code:
onClipEvent(enterFrame){
if(this.hitTest(_root.bad))(
_root.healthBar._xscale) = CurrentHealth / MaxHealth * 100;
}

_________________
Image
super smash bros blits(working title)-1% done
new flash game


Mon May 04, 2009 10:29 am
User avatar

Joined: Wed Apr 29, 2009 11:28 pm
Posts: 323
Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
HA HA HA, I FORGOT THAT YOU CAN'T PUT s*** IN BOLD FOR CODE TAGS.


Code:
onClipEvent(enterFrame){
if([b]this.[/b]hitTest(_root.bad))(
_root.healthBar._xscale = [b]_root.healthBar._xscale[/b] - 1[b];[/b]
)
}


Also, what I meant was using that code I posted to update the bar. As in, make a current and max health variable, then in the hittest thing just do this

Code:
onClipEvent(enterFrame){
if(this.hitTest(_root.bad))(
CurrentHealth = CurrentHealth - 1;
)
}

_________________
Image

Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper.

READ THIS: http://ipgd.freehostia.com/copypasta.html


Mon May 04, 2009 10:36 am
User avatar

Joined: Tue Oct 28, 2008 1:37 pm
Posts: 300
ok ive managed to make that code work (dont know the difference) but what i realy want is it to stop when the x scale is 0 and my char to go to his dead animation

_________________
Image
super smash bros blits(working title)-1% done
new flash game


Mon May 04, 2009 11:04 am
User avatar

Joined: Wed Apr 29, 2009 11:28 pm
Posts: 323
Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
Code:
if(CurrentHealth > 0){
 _root.healthBar._xscale) = CurrentHealth / MaxHealth * 100;
}else{
_root.Character.gotoAndPlay("dead");
}

_________________
Image

Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper.

READ THIS: http://ipgd.freehostia.com/copypasta.html


Mon May 04, 2009 11:13 am
User avatar

Joined: Tue Oct 28, 2008 1:37 pm
Posts: 300
Code:
onClipEvent(enterFrame){
   var CurrentHealth:Number=10;
   var MaxHealth:Number=10;
if(this.hitTest(_root.bad))(
_root.healthbar._xscale) = _root.healthbar._xscale - 10;
}
onClipEvent(enterFrame){
if(this.hitTest(_root.bad))(
CurrentHealth = CurrentHealth) - 10;
}
onClipEvent(enterFrame){
if(CurrentHealth > 0){
_root.healthBar._xscale) = CurrentHealth / MaxHealth * 100;
else{
_root.Character.gotoAndPlay("dead");
}
if(CurrentHealth > 0){
_root.healthbar._xscale) = CurrentHealth / MaxHealth * 100;
}else{
_root.Character.gotoAndPlay("dead");
}

ive tryed to stitch all the codes together but here are the problems
Code:
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 59: Syntax error.
     _root.healthBar._xscale) = CurrentHealth / MaxHealth * 100;

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 64: Syntax error.
     _root.healthbar._xscale) = CurrentHealth / MaxHealth * 100;

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 65: 'else' encountered without matching 'if'
     }else{

Total ActionScript Errors: 3     Reported Errors: 3

_________________
Image
super smash bros blits(working title)-1% done
new flash game


Mon May 04, 2009 11:34 am
User avatar

Joined: Mon Aug 11, 2008 1:09 pm
Posts: 166
Location: England lol
Gender: Male
Currently Playing: Minecraft
Code:
onClipEvent(enterFrame){
  if(hitTest(_root.bad))(
    _root.healthBar._xscale-=1
  )
}


Isn't this supposed to have }'s instead of ('s and )'s to end an if statement... you failed to correct that and have seemed to adopt that method of doing it in every code amendment.

Code:
onClipEvent(enterFrame){
  if(hitTest(_root.bad)){
    _root.healthBar._xscale-=1
  }
}


Mon May 04, 2009 11:38 am
WWW
User avatar

Joined: Wed Apr 29, 2009 11:28 pm
Posts: 323
Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
That won't work. The variables need to be declared on the frame itself. Otherwise it'll just set them to 10 every frame.

That, and you stuck onClipEvent handlers inside of other onClipEvent handlers. I went into flash and debugged the thing myself.

Code:
onClipEvent(enterFrame){
   var CurrentHealth:Number=10;
   var MaxHealth:Number=10;
   _root.healthbar._xscale = CurrentHealth / MaxHealth * 100;
   if(this.hitTest(_root.bad)){
      CurrentHealth = CurrentHealth - 10;
   }
   if(CurrentHealth > 0){
      _root.healthBar._xscale = CurrentHealth / MaxHealth * 100;
   }else{
      _root.Character.gotoAndPlay("dead");
   }
   if(CurrentHealth > 0){
      _root.healthbar._xscale = CurrentHealth / MaxHealth * 100;
   }else{
      _root.Character.gotoAndPlay("dead");
   }
}


Move the currenthealth and maxhealth variable to the frame itself and use this code.

Code:
onClipEvent(enterFrame){
   _root.healthbar._xscale = _root.CurrentHealth / _root.MaxHealth * 100;
   if(this.hitTest(_root.bad)){
      _root.CurrentHealth = _root.CurrentHealth - 10;
   }
   if(_root.CurrentHealth > 0){
      _root.healthBar._xscale = _root.CurrentHealth / _root.MaxHealth * 100;
   }else{
      _root.Character.gotoAndPlay("dead");
   }
   if(_root.CurrentHealth > 0){
      _root.healthbar._xscale = _root.CurrentHealth / _root.MaxHealth * 100;
   }else{
      _root.Character.gotoAndPlay("dead");
   }
}

_________________
Image

Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper.

READ THIS: http://ipgd.freehostia.com/copypasta.html


Mon May 04, 2009 11:46 am
Display posts from previous:  Sort by  
 [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.