Adding health to a player

Get help using Construct 2

Post » Sat Apr 14, 2012 6:54 pm

I think I may have figured it out. Currently testing.

Yep figured it out. Turns out I wasn't thinking things through. I know this is probably an extremely basic thing but I'll write out how I did it just in case someone searches for this exact same thing (what are the chances someone doesn't know how to do this right? lol /facepalm)

Give your player character an instance variable with however much health you want him to have. Create an event and select your player character, scroll down to instance variables and select compare instance variable. Select your characters health instance variable from the drop down menu (if it doesn't appear you didn't create one). Under comparison select Less than or equal and for the value select 0. Next add an action, select your player, scroll down to misc and select destroy. This says that when your characters life is less than or equal to zero, destroy him. Just follow the other tutorials if you want to create a health display. But in short create a global variable with the same value as your players starting health, then every time your player gets hit subtract 1 from the global variable as well. I don't know how to do it for platform games where you give them multiple retries, this is more for games similar to the Ghost Shooter beginners tutorial.

====== Original Post =======

Hello again and sorry for asking for help again so soon. I want to add health to my player and display it as well. The problem is that when I try to set text it doesn't accept instance variables? I honestly can't even believe I'm having issues figuring this out. I thought this would have been the easiest part.

I have an instance variable for the player sprite called PlayerHealth set to 25. I created a text object called PlayerHealth as well. When I try to set text "HP: " & PlayerHealth to display the HP it says 'PlayerHealth' needs an expression after it, this is an object name so you need a dot and an expression name after it.

I tried to make a global variable instead of instance for the player to use but I can't add that to the player.

Basically I want to subtract health when monsters collide with the player, not instantly destroy the player, and it seems I can only use instance variables to do that but I am not sure how to get the health to display. I know I'm missing something, or several things, but I am not sure what. Any chance someone can help out?

Right now this is what I want to add to the player:
[QUOTE=Yann] Or by using the usefull clamp[/QUOTE]

I get that it's only a display (which is using global variables), I just don't know how to actually add health to the player properly so it gets subtracted when monsters collide with the player.Seraphyx2012-04-14 20:28:25
Posts: 10
Reputation: 2,279

Post » Sat Apr 14, 2012 8:41 pm

Last edited by Yann on Sun Sep 14, 2014 8:35 pm, edited 1 time in total.
Posts: 1,479
Reputation: 16,336

Post » Sun Apr 15, 2012 10:14 pm

The best part is when you start figuring out how things work! I treat it like meta-game developing, and I'm gaining experience! :)
Posts: 66
Reputation: 4,515

Post » Mon Apr 16, 2012 3:53 pm

[QUOTE=Cpryd001] The best part is when you start figuring out how things work! I treat it like meta-game developing, and I'm gaining experience! :)[/QUOTE]

^^ this is the purpose.
Image Image Image Image Image Image
Posts: 1,166
Reputation: 18,090

Post » Tue Apr 24, 2012 8:43 pm

Posts: 15
Reputation: 492

Return to How do I....?

Who is online

Users browsing this forum: Eltondrknss, Fedemcuru, Swivels, vargazso and 16 guests