Health Variable Not Changing

You must understand the Game Editor concepts, before post here.

Health Variable Not Changing

Postby code4242 » Thu Aug 25, 2011 2:42 am

I'm having a problem with my battle system. Basically, I have a collision event on the attack Actor that activates when it collides with the enemy. Here is the code, where "tech1" is the type of attack it is, and "p2hpbar" is the enemy's health points. "p1atk" and "p2def" are just stats which I know for a fact do not equal zero.

Code: Select all
if (tech1==1)
{
    p2hpbar-(2*p1atk/p2def);
    DestroyActor("Event Actor");
}


Now for some reason, p2hpbar doesn't change when the actor collides with the enemy. Any solutions or tips? This is key to my game.
Current project: Teratism
User avatar
code4242
 
Posts: 40
Joined: Tue Dec 11, 2007 9:01 pm
Location: Sitting at my laptop :D
Score: 0 Give a positive score

Re: Health Variable Not Changing

Postby skydereign » Thu Aug 25, 2011 8:32 am

The reason the hp never changes is that you never change it. You need to have an assignment operator (=). So, replace the code with this.
Code: Select all
if (tech1==1)
{
    p2hpbar-=(2*p1atk/p2def);
    DestroyActor("Event Actor");
}

That way it decreases p2hpbar by (2*p1atk/p2def).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Health Variable Not Changing

Postby schnellboot » Thu Aug 25, 2011 8:33 am

Code: Select all
if (tech1==1)
{
    p2hpbar-=(2*p1atk/p2def); //you have to use -=
    DestroyActor("Event Actor");
}
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Health Variable Not Changing

Postby code4242 » Thu Aug 25, 2011 1:26 pm

Oh! I see! Thanks. I'd have thought that I would have tried something like that, but apparently not. Thanks again! :D

So, just a question, what is it actually trying to do the way I have it set up? It's not sending me an error.
Current project: Teratism
User avatar
code4242
 
Posts: 40
Joined: Tue Dec 11, 2007 9:01 pm
Location: Sitting at my laptop :D
Score: 0 Give a positive score

Re: Health Variable Not Changing

Postby lcl » Thu Aug 25, 2011 6:07 pm

code4242 wrote:Oh! I see! Thanks. I'd have thought that I would have tried something like that, but apparently not. Thanks again! :D

So, just a question, what is it actually trying to do the way I have it set up? It's not sending me an error.

Well, it's not doing anything. Because that is just calculation, but you're not setting anything have the value of that calculation. :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Health Variable Not Changing

Postby code4242 » Thu Aug 25, 2011 7:04 pm

Oh, alright. Thanks for the tip! :)
Current project: Teratism
User avatar
code4242
 
Posts: 40
Joined: Tue Dec 11, 2007 9:01 pm
Location: Sitting at my laptop :D
Score: 0 Give a positive score

Re: Health Variable Not Changing

Postby Game A Gogo » Thu Aug 25, 2011 8:43 pm

lcl wrote:
code4242 wrote:

Well, it's not doing anything. Because that is just calculation, but you're not setting anything have the value of that calculation. :D


Well it does something... Just something useless.

It will waste cpu cycles trying to figure out what the equation equals to, but since you're not telling him what to do with the found value, it stops there and proceeds to the next line :)
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

Re: Health Variable Not Changing

Postby code4242 » Thu Aug 25, 2011 10:23 pm

Haha, nothing better than wasting some cpu to figure out equations that don't mean anything. :lol:
Current project: Teratism
User avatar
code4242
 
Posts: 40
Joined: Tue Dec 11, 2007 9:01 pm
Location: Sitting at my laptop :D
Score: 0 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest