How do I delete previously created instance?

Get help using Construct 2

Post » Thu Sep 21, 2017 2:22 pm

Hi. I tried to search the forums but found none to help me solve. As the title says, how do I delete previously created instance of an object? I provided an image of what I am currently working on. The gray square acts as the bullet that when on clicked and if aligned, it will move at the brown circle and rotate there, and then another circle should be created by being spawned at those small red circles. But then I wanted the blue circle to be deleted once the bullet moves to another. I'm stuck at the moment and can't seem to find a way to do it. Any help would be appreciated! :)

Image
B
16
S
4
G
1
Posts: 19
Reputation: 1,200

Post » Thu Sep 21, 2017 2:42 pm

You spawn a new blue circle and you want the previous blue circle to be deleted?

If you only have 1 circle at any time on the screen, then simply destroy it first and then spawn a new one.

If you have many circles and need to delete only the last created instance, you can use a variable to store its UID.
When you need to delete last instance, pick it by UID and destroy.
When you spawn a new one, save its UID to that variable.
Check out my awesome game Doptrix
B
17
S
9
G
30
Posts: 525
Reputation: 17,349

Post » Thu Sep 21, 2017 2:53 pm

Hi dop2000 thanks for reply! At the moment there will only be two circles present in the screen, as the previous one should be deleted. I am not really good with coding and your suggestion seems complicated for me, but I will do my best to try that. Never thought of using a variable to store UID's.
B
16
S
4
G
1
Posts: 19
Reputation: 1,200

Post » Thu Sep 21, 2017 3:16 pm

It's simple. Create a global variable LastCircleUID.
After you spawn a new circle do this:
LastCircleUID=circle.UID

When you need to delete a circle with this UID, do this:
Pick circle with Unique ID : LastCircleUID
circle -> Destroy
Check out my awesome game Doptrix
B
17
S
9
G
30
Posts: 525
Reputation: 17,349



Return to How do I....?

Who is online

Users browsing this forum: Blendi1223, jatin1726, Kyatric and 26 guests