How do I Destroy Object on Return Pressed

Get help using Construct 2

Post » Tue Nov 15, 2016 10:18 pm

Hello. In my game that I am making, I was trying to make an object that is destroyed by the sprite colliding with it and then destroying it when Enter (return) is pressed. I have tried to attempt it but it doesn't get the job done smoothly and you have to jump on top of the object in a certain spot in order for it to work. Any advice on how to fix this?
Thanks
B
3
Posts: 11
Reputation: 201

Post » Wed Nov 16, 2016 2:23 am

Sorry, but what are you trying to achieve?
When is the object supposed to be destroyed? When you press Enter after it has collided?

If that is the case, you can simply store the collided object's UID in a variable (global or instance doesn't matter).
You do so by adding an event "Player: On collision with [object]".
Underneath that, add an action "Set value "collisionUID" (your variable) to [object].UID".
(Since the colliding [object] gets picked by the event, the correct object's UID will be stored.

Now, you add your keyboard event "On Return pressed".
As a sub-event, add an expressional picking condition, picking [object] with the expression [object].UID = collisionUID.
On that condition, add the action [object]: Destroy.
Done.

____________________

You can also add a condition to the keyboard pressing event: "If 'CollisionUID' is not 0" and an action after the destroying action: "Set 'CollidionUID' to 0".
This prevents destroying an [object] that already has been destroyed.


If you need further help or a .capx, give me a shout.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Wed Nov 16, 2016 10:26 pm

randomly wrote:Sorry, but what are you trying to achieve?
When is the object supposed to be destroyed? When you press Enter after it has collided?

If that is the case, you can simply store the collided object's UID in a variable (global or instance doesn't matter).
You do so by adding an event "Player: On collision with [object]".
Underneath that, add an action "Set value "collisionUID" (your variable) to [object].UID".
(Since the colliding [object] gets picked by the event, the correct object's UID will be stored.

Now, you add your keyboard event "On Return pressed".
As a sub-event, add an expressional picking condition, picking [object] with the expression [object].UID = collisionUID.
On that condition, add the action [object]: Destroy.
Done.

____________________

You can also add a condition to the keyboard pressing event: "If 'CollisionUID' is not 0" and an action after the destroying action: "Set 'CollidionUID' to 0".
This prevents destroying an [object] that already has been destroyed.


If you need further help or a .capx, give me a shout.



I would appreciate a .capx because I'm not exactly sure how you apply what you said :?
B
3
Posts: 11
Reputation: 201

Post » Thu Nov 17, 2016 11:09 pm

Here you go:
Download
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 11 guests