Error on checking variables

Get help using Construct 2

Post » Wed Apr 18, 2012 2:47 am

Right now in my game I have a variable that when PHealth is 0 or less subtract 1 from lives and reset health to 10, For some reason it subtract 1 from lives and reset the health total but wont stop subtracting from lives. I can seem to stop it. Can someone take a look and see where my error is. Also to skip around the game 1 takes you to first level, 2 to second level and 3 to last level.   Thank you. I am also still having trouble with enemies all trying to attack me when one finds me instead of just the one within range.
B
4
G
1
Posts: 15
Reputation: 1,030

Post » Wed Apr 18, 2012 3:07 am

You did not post a capx, so hard to look at anything.

Nevertheless from what you describe, you have an event with a condition PHealth <= 0.
When this event executes it acts on the values of some variables.
You say you reset Health to 10.
But the variable PHealth is still <= 0. So the next tick, when C2 test this condition, it will be true again and so the event executes again, etc...

What you need is, in this very event, to set PHealth to a different value than 0. As last action, set PHealth to 10 and you'll be sure that the very tick the event executes since its condition is true, an action makes it so that the next tick the condition will be false and the event won't execute again.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Wed Apr 18, 2012 3:48 am

whoops. I Thought I did.Game I am having both Health and Phealth resetting to 10. Maybe I missed something. Also is there a way to set an enemy to move on walls.Gallis2012-04-18 03:50:36
B
4
G
1
Posts: 15
Reputation: 1,030

Post » Wed Apr 18, 2012 7:30 pm

Any ideas?
B
4
G
1
Posts: 15
Reputation: 1,030

Post » Wed Apr 25, 2012 2:18 am

I still can't figure out the issue.
B
4
G
1
Posts: 15
Reputation: 1,030

Post » Wed Apr 25, 2012 3:29 pm

The problem is that the event sheet is run every tick. In the condition where the Player.PHealth <= 0, you're waiting 1.5 seconds and then 0.3 seconds. While it's waiting, the event sheet is running again and again and continuously subtracting 1 from lives.
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 29 guests