How do I destroy 2 objects at the same time?

Get help using Construct 2

Post » Fri Jan 27, 2017 4:44 pm

Hi,
I'm currently creating an isometric game and I have some problems with creating and destroying the square map objects and the projection objects at the same time.
At the moment I have only one enemy which has a solid map object for collision detection and the overall game logic. Also it has an isometric projection object which is only for the isometric graphics. When the game creates an enemy, an instance variable for the map object is set to a random number and the same one is set to the isometric objects instance variable. So when an enemy is destroyed (the map object) it will search for the iso object with the same random number and destroy that one aswell. This system works but has some problems when I try to destroy too many enemies at the same time. Sometimes the isometric object is still there when the map object is already destroyed. Also I had invisible enemies sometimes when the map object was still there although the isometric object was already gone.
Maybe someone has an idea of what the cause for this problem could be? Or even a better way to do this whole thing?
I already had a look at the containers, but I would like to have only one solid map object and one isometric enemy object with different animations, which will have parameters to adapt to different enemy types. This won't work with containers though I think. The goal is to have a dynamic system to easily add more and more different enemy types to the game.
Any help is appreciated!
Thanks!
Image
B
5
S
3
Posts: 193
Reputation: 1,063

Post » Fri Jan 27, 2017 7:15 pm

I think containers.

Besides that. Lets gamble. You must have a condition somewhere that picks several map objects, and you follow up by picking the iso objects that matches with only the first instance of map object in the picklist. A 'for each object" will solve that. Or a 'on collision' in stead of 'is overlapping'.

Say you have several bullets somewhere in the air, or a dense pack enemy's.
Now the condition 'bullet is overlapping enemy' will result in a picklist containing many bullets and many enemy's.

map bullet is overlapping map enemy
____for each map bullet (sub event)
____pick iso bullet with the same instance variable as map bullet (same event)
..................................action ... destroy iso bullet
____for each map enemy (new sub event)
____pick iso enemy with the same instance variable as map enemy (same event)
..................................action ... destroy iso enemy
____an empty sub
..................................action ..destroy map bullet
..................................action ..destroy map enemy
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jan 27, 2017 7:46 pm

have you try to create a function and pass different parameters?
B
36
S
9
Posts: 63
Reputation: 2,225

Post » Fri Jan 27, 2017 7:48 pm

You could try having an instance variable in both the map object and the iso object that stores each others uid. You can then get a direct reference to the paired objects from both directions.
Image
B
30
S
9
G
3
Posts: 171
Reputation: 3,329

Post » Fri Jan 27, 2017 9:12 pm

First of all thank you all for your answers!
I've now replaced every "Pick" Condition with a "For each" loop as @99Instances2Go suggested. After that there was a slight improvement in the invisible enemy count :D Now there was a bug where only some invisible enemies appeared sometimes with negative health values. I fixed it by moving the action for the destruction of the map objects directly after the Health <= 0 condition as it was placed after the id test condition before. So because there was no iso object to be found it didn't delete them. It seems like the game sometimes still fails to destroy the map objects but this at least destroys them in the next tick or so.
I hope this will keep working as I add more content :D
Thanks again!
Last edited by aquadijoib on Fri Jan 27, 2017 9:43 pm, edited 1 time in total.
Image
B
5
S
3
Posts: 193
Reputation: 1,063

Post » Fri Jan 27, 2017 9:18 pm

aquadijoib wrote:I've now replaced every "Pick" Condition with a "For each" loop as @99Instances2Go suggested!


I did ?

No.
I suggested to run trough all picked objects with a 'for each'.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jan 27, 2017 9:29 pm

Well..
I tried using the "Pick object by comparison" and "For each" now and it seems to work the same as with the "compare variable" condition I just used for this.
I guess there is multiple ways to do this :)
Thanks again!
Image
B
5
S
3
Posts: 193
Reputation: 1,063

Post » Fri Jan 27, 2017 9:42 pm

I did it like this:
--(condition) For each "map_enemy" & map_enemy.health <= 0
---- (action): "map_enemy" destroy
____-- (subevent) For each "iso_enemy" & iso_enemy.id = map_enemy.id
____---- (action) "iso_enemy" destroy

When I understand correctly you wanted me to put the "Pick by comparison" in the place of map_enemy.health <= 0 right? I think this is the same though.
Image
B
5
S
3
Posts: 193
Reputation: 1,063

Post » Fri Jan 27, 2017 9:52 pm

General illustration of the problem that you created:
https://www.dropbox.com/s/4eju1pbtlzrir ... .capx?dl=0

Adjustment that i suggested:
https://www.dropbox.com/s/5wl3o5nbpe3a8 ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jan 27, 2017 9:57 pm

aquadijoib wrote:I did it like this:
--(condition) For each "map_enemy" & map_enemy.health <= 0
---- (action): "map_enemy" destroy
____-- (subevent) For each "iso_enemy" & iso_enemy.id = map_enemy.id
____---- (action) "iso_enemy" destroy

When I understand correctly you wanted me to put the "Pick by comparison" in the place of map_enemy.health <= 0 right? I think this is the same though.


Nope.
The problem happens on the moment that the enemy is losing health.
As i said i gambled, you dont give that much info.

I suppose it is with bullets, and you use 'on overlap'.

Bullet is overlapping map_enemy
For each map_enemy
...................... do your health thing

I should have known that they do not directly get destroyed. Now, this is all it needs.
But to be save (not sorry) you better keep the for each when destroying. After all it is possible that two enemy's go dead at the same time.

Then the follow up is

map_enemy.health <= 0
For each "map_enemy"
"iso_enemy" ... compare instance variabe ... iso_enemy.id = map_enemy.id
---- (action): "map_enemy" destroy
--------------- "iso_enemy" destroy
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to How do I....?

Who is online

Users browsing this forum: AllanR, Artcadev and 12 guests