PDA

View Full Version : How to make the value decrease?



farban
March 8th, 2009, 06:26 PM
Heya there just havig a stupid problem where the health on my game increases on my game instead of decreases when the player is hit.

here is the source code

HUD.as (Scoreboard)




private var stageRef:Stage;
public var s_score:Number = 0;
public var s_kills:Number = 0;
public var s_health:Number = 0;




health.text = "100";




public function updateHits(value:Number) : void
{
s_health += value;
health.text = String(s_health);
}



}

}engine.as (game engine)


private function shipHit(e:Event) : void
{
theHUD.updateHits(1);
}thanks for any help

m90
March 8th, 2009, 06:33 PM
How about:



s_health -= value;

McGuffin
March 8th, 2009, 06:34 PM
Well obviously it's going to increase, you're passing a positive number and adding it to a positive number. Either of the following will do the trick:

1.


private function shipHit(e:Event) : void
{
theHUD.updateHits(-1);
}


2.


public function updateHits(value:Number) : void
{
s_health -= value;
health.text = String(s_health);
}


Both will decrease health. Probably better to use 1 rather than 2, because then you won't need to pass negative numbers to increase health.

farban
March 8th, 2009, 06:51 PM
Doesnt seem to make a change and since this project has to be in soon i just have to compromise and make the text feild damage instead. Unless anyone has anymore solutions.