Track multiple enemies health?

Get help using Construct 2

Post » Wed Aug 15, 2012 11:25 pm

Hello,

I was following an excellent tutorial by Ayzhong 1945 Tutorial Part 6

and ran into an issue. In his tutorial he is explaining how to make a 1945 clone, and had us create two different enemies. One was a basic one hit plane, and the other was a 5 health Submarine. Whenever there are more than one plane enemy on the screen, and you kill it, the others do not die.

However with the submarine, which has an "instance variable" of 5, they will sometimes all die together when you kill one, or sometimes they do not.

If you need me to upload the capx let me know. Otherwise any suggestions would be appreciated.

Thanks. Lordxorn22012-08-15 23:26:24
B
13
S
3
G
5
Posts: 12
Reputation: 3,532

Post » Wed Aug 15, 2012 11:48 pm

This is one of the main issues of Construct 2, and I hope it will be solved with better support to IIDs and UIDs, as said here: http://www.scirra.com/forum/suggestion-show-i-uids-for-selected-objects_topic55109_post344056.html#344056

So, you'll ran in two type of problems, and all the answers are "bad" in my personal opinion.

Or you create the enemies and keep tracking them with UID or IID, so, you can manipulate their health as well, but when you destroy one of them, you'll modify the index and flush their UIDs or IIDs.

The second method is keep them invisible after their health goes 0. This will improve the number of objects on the canvas, but will not reset the UIDs and IIDs.

I personally did a workaround for it by this way:

When the player shot on an enemy and hit him, set the to drop the health of the nearest enemy of that projectile. It's working nice, but when two enemies are hit by the projectile, it only drop the health of the nearest.

So, I'll improve the code to check the overlapping enemies, so, if the enemy is overlapped, drop his health.

This is working because one thing Ashley said on his Manual here: http://www.scirra.com/tutorials/37/beginners-guide-to-construct-2/page-6

So, if you create a new enemy, the engine will treat this enemy as a unique object (UID and IID), but you can know where it is and manipulate him by making a conditional meeting your necessity, so, when the bullet hit the monster, that specific monster, inside that conditional, will lose health or die. ^^

A long and terrible explanation, but I hope it's understandably!
ImageImageImageImageImageImage
B
93
S
20
G
12
Posts: 1,212
Reputation: 18,482

Post » Thu Aug 16, 2012 12:04 am

It is a little overwhelming at first glance, but I will dive into this deeply tonight. Thanks to your two workarounds I will see what I can come up with.

Thank you! =)
B
13
S
3
G
5
Posts: 12
Reputation: 3,532

Post » Thu Aug 16, 2012 12:09 am

you should upload the cap file, ill take a look at it, it might be simpler than that
B
15
S
2
G
3
Posts: 50
Reputation: 1,863

Post » Thu Aug 16, 2012 12:23 am

I don't understand - instance variables are perfect for things like health. They are kept independently for each instance, and an event like "If health < 0, destroy sprite" will individually destroy sprites which run out of health, and never affect all of them at once.

Are you sure there isn't a mistake in the tutorial, or a mistake in your events?
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Thu Aug 16, 2012 12:39 am

B
13
S
3
G
5
Posts: 12
Reputation: 3,532

Post » Thu Aug 16, 2012 1:10 am

There is a mistake in the events. Its a picking issue like I expected.

You need to have the ACTION that subtracts from the health variable directly connected the the CONDITION of the bullet hitting the submarine. That way the game knows exactly which submarine to subtract health from, the submarine that is colliding with the bullet. As it stands now, the game doesn't exactly know which submarine you are referring to, so when any submarine is hit, they all lose some health. Those two have to be tied together.
B
15
S
2
G
3
Posts: 50
Reputation: 1,863

Post » Thu Aug 16, 2012 1:14 am

Ahh ok , thank you very much. =)
B
13
S
3
G
5
Posts: 12
Reputation: 3,532

Post » Thu Aug 16, 2012 1:53 am

[QUOTE=Ashley] I don't understand - instance variables are perfect for things like health. They are kept independently for each instance, and an event like "If health < 0, destroy sprite" will individually destroy sprites which run out of health, and never affect all of them at once.

Are you sure there isn't a mistake in the tutorial, or a mistake in your events?[/QUOTE]

That's it what I tried to say boss:
[QUOTE]So, if you create a new enemy, the engine will treat this enemy as a unique object (UID and IID), but you can know where it is and manipulate him by making a conditional meeting your necessity, so, when the bullet hit the monster, that specific monster, inside that conditional, will lose health or die. ^^[/QUOTE]

I mean this is a treat when you have, for example, a rocket with smoke, where the smoke is attached to the rocket.

To explain this topic, you can set individual instance variables for each smoke and each rocket, when creating them. Mean "instances" as "index numbers stored as variables".

When the rocket is destroyed, make sure to destroy the smoke with the same index number as the destroyed rocket.

How to set instances: Instances CAPX
Live sample: Instances HTML5

And all without UID and IID, you really don't need to care about them. They are very much volatile ^^TELLES08082012-08-16 01:55:35
ImageImageImageImageImageImage
B
93
S
20
G
12
Posts: 1,212
Reputation: 18,482


Return to How do I....?

Who is online

Users browsing this forum: abdalghani and 23 guests