How do I make health system

Get help using Construct 2

Post » Mon Aug 07, 2017 5:43 pm

I am trying to make basketball game in which player tries to score as many balls into net. The player starts with 3 in upper left hand corner with a ball showing indicating that if he misses a shot, 2 will then show up, another shot missed would mean it would go down to 2 and then another shot missed would mean it would go down to 1 showing up in upper left hand corner until reaches 0. How all would you guys recommend me going about setting this health part of my game up?
B
12
S
3
G
3
Posts: 36
Reputation: 2,274

Post » Mon Aug 07, 2017 10:38 pm

By using a global variable called Health, with initial value 3.
Display it on a text object somewhere Set text ""&Health.
When player misses shot, subtract 1 from Health.
B
47
S
18
G
84
Posts: 2,261
Reputation: 49,776

Post » Mon Aug 07, 2017 11:21 pm

Could you provide a capx with this and/or another method of achieving the same effect. I tried this and it didn't work for me.
B
12
S
3
G
3
Posts: 36
Reputation: 2,274

Post » Mon Aug 07, 2017 11:58 pm

Using variables to control many things (like health, ammo, etc) is a fundamental and basic part of construct 2, and programming in general.

Once you learn how to use these simple but powerful tools, it will all make sense.

I can try to make an example today (I expect a fairly quiet day in the office today) but I will have to see if time does in fact allow.

Essentially, you need to create a global variable on your event sheet (right click on the event sheet and add global variable) then name it HEALTH. Set the initial value to 3.

Anytime you want to subtract 1 from health, you have your condition for doing so... example: player collides with enemy ->(action= subtract 1 from global variable HEALTH).

Then you have another event that checks what the health is at: global variable health = 0 ->(action: destroy player)

You can use variables to track all kinds of stuff that you need to be, well, variable... so simple yet so powerful when used in certain ways.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Tue Aug 08, 2017 8:00 am

Like this? Should probably be in beginner's questions if you're not sure on how to use variables. https://www.dropbox.com/s/v3q2c86ftl6fa ... .capx?dl=0
B
47
S
18
G
84
Posts: 2,261
Reputation: 49,776


Return to How do I....?

Who is online

Users browsing this forum: Casaubon, max2612 and 6 guests