Plans for automatic "pick instance UID" system?

Discussion and feedback on Construct 2

Post » Thu Jan 24, 2013 9:20 pm

I have yet to successfully make a game where one of multiple instances of the same type can be destroyed.

example:
player shoots one of the seven attacking drones. Drone has 5HP.
When player has hit the same drone 5 times, all drones are destroyed.

quite a few times I have started making a game where this is needed and every time I end up scrapping the project because I cant figure it out.

Have been searching the forum but cant find a explanation or tutorial detailed enough.

Some of the projects I ended up making with other game making software where this handled automatic. But overall I prefer C2 and thats the reason this post.

Thanks
B
21
S
7
G
4
Posts: 221
Reputation: 5,070

Post » Thu Jan 24, 2013 9:32 pm

You probably just need to use a "For each" loop when checking your Drone's health. That way it checks every instance's HP individually and only deletes the currently picked object in the loop.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Thu Jan 24, 2013 9:39 pm

C2 already can do this. Give the enemies an instance variable and call it "hits". Then use two events like this:

Bullet collides with enemy:
----- add 1 to Enemy "hits"
----- destroy bullet

Enemy "hits" >=5
----- destroy enemy
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Thu Jan 24, 2013 9:40 pm

Problem is that every time one of the drones is hit all of them suffers HP loss. A for each loop would make no difference
B
21
S
7
G
4
Posts: 221
Reputation: 5,070

Post » Thu Jan 24, 2013 9:43 pm

The loop is probably not needed, are you using instance variables?
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Thu Jan 24, 2013 9:45 pm

how would that work different than:

Bullet collides with enemy:
----- subtract 1 from Enemy "HP"
----- destroy bullet

Enemy "HP" <=0
----- destroy enemy

its the same thing
B
21
S
7
G
4
Posts: 221
Reputation: 5,070

Post » Thu Jan 24, 2013 9:51 pm

If "HP" started at 5 then yes it is the same.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Thu Jan 24, 2013 9:55 pm

What you just wrote should work fine:

SubtractHP.capx (r116)
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Thu Jan 24, 2013 10:06 pm

[QUOTE=Nimtrix] What you just wrote should work fine:

SubtractHP.capx (r116)[/QUOTE]

hmm.. now Im more confused

Ill check something be back with an update...
B
21
S
7
G
4
Posts: 221
Reputation: 5,070

Post » Thu Jan 24, 2013 10:54 pm

Ok, think I got it. Seems it had something to do with how I used "families". Gonna have to look into that a bit further. Thanx a million for the help..

Hmm this thread should probably been posted in "How do I.." considering how it turned out.. sorry about that
B
21
S
7
G
4
Posts: 221
Reputation: 5,070

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 4 guests