On Object Clicked firing more than once

Discussion and feedback on Construct 2

Post » Thu Nov 22, 2012 4:48 am

I'm a little confused over the intended behaviour of the situation below.

I have a sprite with 3 animations. On the condition "On Object Clicked" I set the animation to the second state. The strange thing is that then the event directly below it also fires.


Sample Capx

Now I understand that because of the green arrows these events will fire immediately, plus I understand the order the scripting language runs in (top to bottom). What I would have expected though is that the second event should fail because I've not clicked on the second animation yet - the mouse button is still down, I've not released it. If these were "on mouse down" conditions I could understand, but they are on mouse click and I've only clicked once. I only expect the event to fire once because of this.

Should this be working or am I thinking about this the wrong way?
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Thu Nov 22, 2012 8:59 am

This is almost similar to another case in here:

http://www.scirra.com/forum/r103-new-spawned-obj-is-triggered-by-mouse-click_topic56718.html?KW=

A trigger is called on an object that is "newly created" on the same frame when the click happens.

I thought this is kinda weird too,
but I guess when you read above thread the conclusion is, don't depend on this kind of behaviour.
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Thu Nov 22, 2012 10:11 am

put an "else" between them ;)


[
Left button clicked on sprite

- if animation 1
- else if animation 2
- else if animation 3
]superkew2012-11-22 10:12:34
B
22
S
7
G
3
Posts: 189
Reputation: 4,270

Post » Thu Nov 22, 2012 4:48 pm

Yeah that's the way it works. You might think it should check the condition alongside the mouse trigger at the moment you click; but it just checks for mouse clicks and then goes through each mouse click event one at a time checking the other conditions. So whether a later event runs depends on what happens in a previous event.

What you have there is the equivalent of:


And the solution like superkew says is:
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Fri Nov 23, 2012 2:05 am

I'll try setting up the else statements and see how that goes.

I have to agree with the thread that Potato linked to, R102 made more sense.

I understand that, as far as the tick is concerned, animation state two has been set and the mouse has been clicked. But it should be able to determine that I didn't click on animation two, I clicked on animation one. As far as I can tell that is incorrect to register me clicking on animation state two.

It might be hard to solve this behind the scenes, but I'm edging from 70% convinced to 98% convinced that this is a bug
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Fri Nov 23, 2012 2:37 am

@boolean - no, this is not a bug. Let me explain the interpretation of the logic that you did by Construct 2. In the same tick, the object was clicked. The first event states the condition "object clicked"(true) and "StateOne"(true), set animation to "StateTwo". So animation is now at "StateTwo" but the processing of the logic in the tick is not over yet. The next event, "Object Clicked"(true because it is still in the same tick and the condition is true in this tick) and "StateTwo"(true because the above event set it so), hence, it also runs. So on and so forth. I hope you understand what you just did.
B
7
Posts: 38
Reputation: 683

Post » Fri Nov 23, 2012 4:25 am

Ahhh, I see. So the condition is saying the object was clicked, and now as the next condition rolls up and the animation has been set, so it's true. Mmm, I guess that does make sense.

Confusing, but you are correct

B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Fri Nov 23, 2012 4:36 am

I had a problem with this when making a toggled option button. Both had the green arrow event for on clicked with secondary condition for if it was off an on.

I solved this problem by adding a wait of 0.1 seconds. That way it would't cycle between the valid options instantly all in the single mouse click. It would wait before considering other variables.
B
20
S
4
G
2
Posts: 124
Reputation: 2,482


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 12 guests