Happen Only Once

Get help using Construct 2

Post » Wed Sep 25, 2013 11:09 pm

When my player has collision with a mushroom, the mushroom does a little dance and a sound plays then she gets health points.

The problem is, if she stands still while touching the mushroom or moves back & forth over it, the events (sound & health points additions) happen over and over again until the animation finishes and the mushroom finally disappears.

How can I make everything only happen once upon collision? It seems if I start with "trigger once while true", the "on collision" event is not available. If I start with "on collision", I am unable to add the "once while true" event on. It doesn't show as an available option.

So how can I limit this event so that the actions only happen once per collision?

Eliyahna2013-09-26 00:55:42
B
18
S
2
Posts: 61
Reputation: 902

Post » Wed Sep 25, 2013 11:27 pm

In your actions you could Disable collision for the mushroom

B
101
S
32
G
12
Posts: 1,549
Reputation: 21,993

Post » Thu Sep 26, 2013 12:43 am

Disabling collisions on the mushroom disables everything resulting in no animation, no health points and well... no collision event.

What did you mean? On the collision event these actions should occur once each. Not zero times each.

B
18
S
2
Posts: 61
Reputation: 902

Post » Thu Sep 26, 2013 1:12 am

Create an instance variable in the mushroom object, and set it's default to 0. In the Collision check, first this set the variable to 1. Your condition should be on collision with mushroom and mushroom.variable = 0.
B
14
S
6
G
1
Posts: 143
Reputation: 1,800

Post » Thu Sep 26, 2013 1:16 am

[QUOTE=Eliyahna]It seems if I start with "trigger once while true", the "on collision" event is not available. If I start with "on collision", I am unable to add the "once while true" event on. It doesn't show as an available option.[/QUOTE] "Trigger once while true" always has to be the last condition in the list. The reason for not being an available option is that "on collision" already is a trigger that only executes once while true (this is indicated with the little green arrow). In your setup you have a wait action set to 3 seconds. Since the mushroom is therefore destroyed after 3 seconds have passed, the player has a lot of time to collide again with mushroom.

Solution:
Split your event. Mark a mushroom in the collision event (e.g. with an instance variable). Nothing else. Another event selects the marked mushrooms, but only if a second instance variable is of the right value (e.g. vanishing = FALSE) and does all the actions like sound playing etc., and finally sets the second IV to another value (e.g. vanishing = TRUE)

EDIT: @wizaerd, I apologize for being sooooo damn slow tulamide2013-09-26 01:17:36
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Thu Sep 26, 2013 1:26 am

Thank you both. @wizaerd - I tried your way first. Works brilliantly.
B
18
S
2
Posts: 61
Reputation: 902

Post » Thu Sep 26, 2013 1:41 am

Of Course the above practice probably the best but a simple solution without variables would be to add an other condition below the "is visible".
That is the "animation is playing", write "Health Up" and invert it. So in essence you will have the following conditions:

->Player on collision with Mushroom
Mushroom is visible
X Is animation "Health Up" playing

and then your actions...

Provided that the animation "Health Up" doesn't end before the wait 3 seconds action that tulamide mention.

Just to be sure you could create an other event that triggers the "destroy" action upon the animation "Health Up" completion.

->On animation "Health Up" finished ---> Mushroom Destroy
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Thu Sep 26, 2013 1:59 am

@eli0s, unfortunately, the "health up" animation is interruptible (in case you have to defend yourself during) so it wouldn't work well.

Oh here's the new working code. "Col" is the instance variable boolean on the mushroom:

Eliyahna2013-09-26 02:00:05
B
18
S
2
Posts: 61
Reputation: 902

Post » Thu Sep 26, 2013 2:04 am

Well, I am glad you worked your way with the optimal solution anyway!
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Thu Sep 26, 2013 3:15 pm

@Eliyahna - I'm glad that worked for you. I don't know if it's the proper way or not, but I started doing it this way a while ago and it works well enough for me. And you know what they say, whatever works...   
B
14
S
6
G
1
Posts: 143
Reputation: 1,800

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests