Page 1 of 1

Whats wrong with this code?

PostPosted: Wed Aug 15, 2007 1:35 am
by arcreamer
hey im trying to make a character have 25 health and each time it gets hit with a bullet for health to go down one so i have in create actor, "health=25;"
then i have on collision with bullet, "health=-1;" and now for the and that was working but now i have to make him die once his health reaches 0 so i did this under draw actor, "(health=25);
if (health==0);
{
DestroyActor("Car_miniboss1");
}

and now he dies a startup... what did i do wrong?

PostPosted: Wed Aug 15, 2007 2:12 am
by Game A Gogo
two things
Code: Select all
Health=35;

should go on a create actor event
and it should be
Code: Select all
if(health==0)
{
    DestroyActor("Car_miniboss1");
}

there must be no ";" after the if thing

PostPosted: Wed Aug 15, 2007 2:27 am
by pixelpoop
and if enemies can do different amounts of damage then you will want to put:
if(health<=0)
So if the health is at 5 and you minus 10, the statement will still execute even though the health never equals zero.

PostPosted: Wed Aug 15, 2007 2:58 am
by arcreamer
thanks guys!

PostPosted: Wed Aug 15, 2007 3:08 am
by arcreamer
i put in that code that game a go said and now when i keep shooting it it never gets destroyed :P i put that code under draw actor and the health=25; under create actor and under collision with bullet health-1; and nothing happens :P what did i do wrong?

PostPosted: Wed Aug 15, 2007 3:09 am
by d-soldier
health-=1;

not health-1;

PostPosted: Wed Aug 15, 2007 3:14 am
by arcreamer
and when i put if(health<=0) he dies at startup :(

PostPosted: Wed Aug 15, 2007 3:15 am
by d-soldier
does he have something in his create-actor script which puts his health above zero?
ie.
health=25;

PostPosted: Wed Aug 15, 2007 3:55 am
by arcreamer
yes it is health=25;

PostPosted: Wed Aug 15, 2007 3:56 am
by arcreamer
my health variable is a global integer, does that have anything to do with it? should i change it?

PostPosted: Wed Aug 15, 2007 4:00 am
by DilloDude
It only matters if more than one actor needs to access health separately. Also make sure its health -= 1 not health =-1. (If it's only 1, you can also use health --).

PostPosted: Wed Aug 15, 2007 4:02 am
by d-soldier
Yes, change health to a actor-variable, as more then one actor (or clone) will be using it.

PostPosted: Wed Aug 15, 2007 4:08 am
by arcreamer
i got it working i had to have collision on any side of bullet, health-=1; instead of just health-1;