(Solved) Condition for Enemy, Score, and Health

Hello there. I am new to Gdevelop and learning things.

I have two objects. One is the player or character. The other is an enemy or obstacle which is not moving but standing still on the ground plane. It is a platformer game.

Now, when the object jumps on top of the enemy, the enemy gets killed and increases the score of the player. But when the player collides with the enemy from the left direction, meaning on the ground plane, the player gets a life deducted. I am trying to create this type of event. I hope you are getting what I am trying to tell.

“Jumps on top of the enemy, the enemy dies. Gets in touch with the enemy when not jumping or falling, meaning when on the ground, the player loses health.”

Now, for the health system, I have created 3 Duplicate Hearts. Each of them contains two animations, one is active and the other is inactive. Active animation means the player has a life. The inactive animation means the heart goes dark grey when the player loses their health.

I also added a scoring system. This is my third-day using GDevelop BTW. The scoring system is a text, I gave it the name HUD_Points. The initial text to display is “000000” meaning six zeroes. I gave it a variable named “TotalPoints” → Number → 0. Then I added it to the top right screen and shifted to a new layer HUD.

I created another text named “Points” with default text and a variable. The variable name is “MoveToPosition”. It’s a number with a value of 0. The purpose of this text is to show the score gained when the enemy gets killed and it gets added to the previous HUD_Points text.

Also, I have added another “Heart” that will be placed on the ground. Player health will be filled if they touch the heart on the ground.

I was able to create events when the players touch the enemy 3 times in a row without getting the recovery heart, game-over the type of thing. I was able to create that. I was also able to create events when the player jumps on top of the enemy, the enemy gets killed and the player’s score increases.

The problem is, when the player touches the enemy on the ground, it is indeed getting killed after 3 hits but the heart animation is not changing. Meaning, it should reduce the heart counts or change the animation to “inactive” hearts. It is not showing that. That animation is not changing. The player will have to count manually how many times they have got hit. How can I solve this problem?

Below is the screenshot of the events that I have set up.

(Part 1):

Please help me solve this error. Thanks in advance.

Here is the screenshot of the remaining parts of the events.

I want to give credits to WinStreak for the first half of the code because he was the one who revealed the events.

So you have your Hearts each assigned an instance variable, 1, 2, and 3 and then if the scene variable Heart is less than the Heart ID it should change to the inactive animation?
Have you tried moving them out from being sub events to the Update_Heart variable and the repeat for each instance, as standalone events? If you have to you can try a Pick all hearts, heart ID is =or < then Scene variable then do this, more then do that.

1 Like

OMG!!! I forgot that part. This is the solution. I added ID variables with strings 1,2, and 3 to each heart and it solved the problem. Thank you so much for reminding me.

1 Like

Yep I thought you were basing it on instance variables and was wondering why it wasn’t working lol. Glad it’s working now.

1 Like

Yeah! Thanks again man.

1 Like