Page 1 of 1

Health Variable Not Changing

PostPosted: Thu Aug 25, 2011 2:42 am
by code4242
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.

Re: Health Variable Not Changing

PostPosted: Thu Aug 25, 2011 8:32 am
by skydereign
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).

Re: Health Variable Not Changing

PostPosted: Thu Aug 25, 2011 8:33 am
by schnellboot
Code: Select all
if (tech1==1)
{
    p2hpbar-=(2*p1atk/p2def); //you have to use -=
    DestroyActor("Event Actor");
}

Re: Health Variable Not Changing

PostPosted: Thu Aug 25, 2011 1:26 pm
by code4242
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.

Re: Health Variable Not Changing

PostPosted: Thu Aug 25, 2011 6:07 pm
by lcl
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

Re: Health Variable Not Changing

PostPosted: Thu Aug 25, 2011 7:04 pm
by code4242
Oh, alright. Thanks for the tip! :)

Re: Health Variable Not Changing

PostPosted: Thu Aug 25, 2011 8:43 pm
by Game A Gogo
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 :)

Re: Health Variable Not Changing

PostPosted: Thu Aug 25, 2011 10:23 pm
by code4242
Haha, nothing better than wasting some cpu to figure out equations that don't mean anything. :lol: