How do I "damage" enemy sprite from a family

Get help using Construct 2

Post » Fri Aug 21, 2015 12:40 pm

Let's say there are 2 or 3 kind of baddies: enemy1, enemy2, etc all of them inside a family called Enemies, and each enemy have his own health different from each other as instance variable, then there is a bullet or fireball or something that hits the enemy and deals X dmg

How do I substract the bullet damage from the enemy health? Do I need to do it manually? I mean bullet on collision with sprite (and do it for each enemy I design) instead of doing it by comparing the UID of the family, or something like that:
Pick enemies.UID --- substract bullet.damage from picked enemy.health
As you can see, I'm not very familiar with UIDs and I cant find something that fits to the case (maybe it does not exists)
Thanks and exuse if i'm asking for something really dumb
B
22
S
9
G
4
Posts: 66
Reputation: 3,775

Post » Fri Aug 21, 2015 1:42 pm

You don't need to compare
Code: Select all
Fireball - On collision with Family1 --> Family1 - Subtract 1 from health


This will only effect the hitted ones. Others in the family wont be affected
B
21
S
8
G
6
Posts: 177
Reputation: 8,134

Post » Fri Aug 21, 2015 1:50 pm

The problem is that every object inside the family has his own health(enemy1.health=50, enemy2.health=100, and so on), so I cant just substract from the family
B
22
S
9
G
4
Posts: 66
Reputation: 3,775

Post » Fri Aug 21, 2015 7:46 pm

give the family the required instance variable not the objects inside.

as it sounds like you have given the variables to the objects rather than to the family have a look at

https://www.scirra.com/tutorials/535/ho ... o-a-family
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Fri Aug 21, 2015 9:22 pm

I dont know if im misunderstanding something but... the actual problem is that every enemy inside the family has a different number for health, so i cant refer to the family instance variable since, if i had one, it would be the same for every object inside the group
If I create a family instance variable, for example enemies.health, this aplies to all instances, enemy.health, enemy2.health, etc So if i want to substract 10 from the enemy health i want this enemy to have enemy.health=50, and enemy2 to have 100 health, for example

I dont know if I'm correctly explaining my problem
B
22
S
9
G
4
Posts: 66
Reputation: 3,775

Post » Fri Aug 21, 2015 10:19 pm

There is a RTS example coming with the software that might help you with this? In that one each object in the family has it's own instance variables with hp.
Image
B
14
S
4
Posts: 145
Reputation: 1,948

Post » Fri Aug 21, 2015 10:39 pm

Thats not what I mean, I need to have a different predefined MaxHealth on each type of enemy

Enemy1.maxhealth=50
Enemy2.maxhealth=100
and so on

So when a bullet hits on the family enemies it substract X from the health from the on-collision-with sprite

The point is just to have 1 condition that affects all enemies but each one with different max health
I know every enemy has his own health if I make a family instance variable, but the same max health too, I want different max health for each enemy

I hope its clear now ^^'

PD: sorry, my fault, I should have mentioned its maxhealth instead of health
B
22
S
9
G
4
Posts: 66
Reputation: 3,775

Post » Sat Aug 22, 2015 7:15 am

say you have 5 sprites called red,blue,green,orange and yellow

you add all 5 to a family "boxes"

then to the family you add instance variables maxhealth and health

now each of the sprites have now also got instance variables maxhealth and health

so at start of layer you can say

red.maxhealth=100
blue.maxhealth=1000
green.maxhealth=500

etc

but you can then say

when members of boxes hit

boxes.maxhealth =boxes.maxhealth-damage

so if the area of damage hist a red, and green sprite then their and only their health will drop
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Sat Aug 22, 2015 7:47 am

here you go - a quick example...

https://db.tt/E7yuO7s6 (r212.2)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Sat Aug 22, 2015 3:39 pm

ok, thats not what I really wanted but this is much easier than manually create an instance variable for each enemy
If linking a sprite instance variable from a family to his family instance variable could be done, it would be awesome (for sure there is a plugin out there)
Thanks a lot for your replies! Made my day @RamPackWobble! I can conclude this as solved
B
22
S
9
G
4
Posts: 66
Reputation: 3,775

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests