Whats wrong with this code?

Non-platform specific questions.

Whats wrong with this code?

Postby arcreamer » Wed Aug 15, 2007 1:35 am

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?
arcreamer
 
Posts: 398
Joined: Tue Jul 03, 2007 4:08 pm
Score: 9 Give a positive score

Postby Game A Gogo » Wed Aug 15, 2007 2:12 am

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby pixelpoop » Wed Aug 15, 2007 2:27 am

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.
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby arcreamer » Wed Aug 15, 2007 2:58 am

thanks guys!
arcreamer
 
Posts: 398
Joined: Tue Jul 03, 2007 4:08 pm
Score: 9 Give a positive score

Postby arcreamer » Wed Aug 15, 2007 3:08 am

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?
arcreamer
 
Posts: 398
Joined: Tue Jul 03, 2007 4:08 pm
Score: 9 Give a positive score

Postby d-soldier » Wed Aug 15, 2007 3:09 am

health-=1;

not health-1;
User avatar
d-soldier
 
Posts: 703
Joined: Sun Apr 08, 2007 2:13 am
Score: 61 Give a positive score

Postby arcreamer » Wed Aug 15, 2007 3:14 am

and when i put if(health<=0) he dies at startup :(
arcreamer
 
Posts: 398
Joined: Tue Jul 03, 2007 4:08 pm
Score: 9 Give a positive score

Postby d-soldier » Wed Aug 15, 2007 3:15 am

does he have something in his create-actor script which puts his health above zero?
ie.
health=25;
User avatar
d-soldier
 
Posts: 703
Joined: Sun Apr 08, 2007 2:13 am
Score: 61 Give a positive score

Postby arcreamer » Wed Aug 15, 2007 3:55 am

yes it is health=25;
arcreamer
 
Posts: 398
Joined: Tue Jul 03, 2007 4:08 pm
Score: 9 Give a positive score

Postby arcreamer » Wed Aug 15, 2007 3:56 am

my health variable is a global integer, does that have anything to do with it? should i change it?
arcreamer
 
Posts: 398
Joined: Tue Jul 03, 2007 4:08 pm
Score: 9 Give a positive score

Postby DilloDude » Wed Aug 15, 2007 4:00 am

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 --).
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby d-soldier » Wed Aug 15, 2007 4:02 am

Yes, change health to a actor-variable, as more then one actor (or clone) will be using it.
User avatar
d-soldier
 
Posts: 703
Joined: Sun Apr 08, 2007 2:13 am
Score: 61 Give a positive score

Postby arcreamer » Wed Aug 15, 2007 4:08 am

i got it working i had to have collision on any side of bullet, health-=1; instead of just health-1;
arcreamer
 
Posts: 398
Joined: Tue Jul 03, 2007 4:08 pm
Score: 9 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest