-
Decreasing health
I'm trying to make a game where I have a "ball" object i move around with the cursor and dodge "block" objects. I have a variable called health and I want to make it so whenever the ball is hit by the block, the ball loses 1 health. here's the code.
health = 10;
if(_root.ball.hitTest(_root.block)){
health--;
}
nothing at all happens when the block hits the ball.
Anyone know what the problem is?
-
Senior Member
First of try this instead,
Actionscript Code:
if(_root.block.hitTest(_root.ball)) { health--; }
Wile E. Coyote - "Clear as mud?"
-
ty, works just fine now. Now I just need to know how to keep the health number from going into the negatives :P
Last edited by wickedwing; 03-06-2010 at 11:38 AM.
-
instead of health--; use a conditional:
Actionscript Code:
health>0?health--:health=0;
That will make sure health doesn't go below 0.
gparis
-
Senior Member
That's quite nice,... could you explain? As in, what the "?" signify as well as the ":". Thanks.
Wile E. Coyote - "Clear as mud?"
-
'?' is if and ':' is else. Shorthand conditionnal for lazy programmers like myself.
gparis
-
Senior Member
Lazy?!! On the contrary... I think it's quite eloquent.
Wile E. Coyote - "Clear as mud?"
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|