mindcontrol wrote:hi, i tried to do this:
On enemy:
-Draw actor -> script editor -> hp == 5;
-Collision with any side of player -> script editor -> hp --;
if(hp<=0) { DestroyActor ("enemy"); }
So i wanted wich the enemy only lose 1 hp for each time he collide, but he die on the first collision, what am I doing wrong?
First, the problem is you wrote
- Code: Select all
hp == 5;
instead of
- Code: Select all
hp = 5;
First compares hp and 5 and if those two are same, the result of this entire expression is 1, else it is 0. But that result is not stored (saved) anywhere and you can't use it in any way, it doesn't affect anything inside your game. Even if it is saved, that's not what you need. So you should write the second statement, which will assign a value 5 to hp. It does what you wanted to do, value of hp is 5.
However, there's one more error. On enemy you should write script in Create Actor, not in Draw Actor. Draw Actor script executes on every frame. If your game has 30 fps, then this script will execute 30 times in a second, or in other words, 30 times in a second 5 will be assigned to hp. It actually doesn't matter much how often it happens. The problem is that you "reset" hp every frame. Write that script in Create Actor. That script executes only when the actor is created.