ForumsProgramming ForumHealth keeps going up what do i do???

3 2419
staticzone
offline
staticzone
67 posts
Nomad

ok i have an apple and the character the character can walk over and touch the apple when he touches it he gets 30 random health but then if he health is already 100 the apple will give him 130. ??? is their any way to make it so his health doesnt go past 100

heres the code on the apple

PHP Code:
onClipEvent (enterFrame) {
}
if (this.hitTest(_root.char)) {
_root.hp_bar += 30+random(30);
if (_root.hitTest.hp_bar <= 100)
}
thats my attempt lol

this is bugging me
is there anyway i can fix this?

thanks

  • 3 Replies
dank
offline
dank
983 posts
Peasant

One, you should have your code inside the clipEvent.
Second, the second if statement should be directly below the first one or it won't do anything.
Third, You shouldn't use hitTest as an instance name as it's reserved in the namespace.
Fourth, Your health will always equal one hundred as long as your touching the apple because the first if will be true as long as you touch the apple.

staticzone
offline
staticzone
67 posts
Nomad

but i touch the apple and it goes past 100

i have this for the hp bar

onClipEvent(enterFrame)
{
this._xscale=_root.char_hp;
if(_root.char_hp<=0)
_root.char_hp=0;
}
onClipEvent (enterFrame) {
this._x=_root.char._x
this._y=_root.char._y
}

staticzone
offline
staticzone
67 posts
Nomad

never mind i figured it out. thanks anyway

Showing 1-3 of 3