Multiple Clicks instead of one, when dragging out and in.

When using just - Cursor is on Sprite, Left mouse button is down and Trigger Once condition to check for a click, dragging in and out of the sprite while the mouse button is held causes multiple clicks to happen since it’s permitted by the logic used. How can it be prevented from happening ?

The same happens when the object is hidden and made visible again while the click is held, which causes the click to be registered again while it reappears, triggering it again.

I use a fix here:

Anyway I want to explain it again, a bit better (so I can redirect here :imp: ). Imagine you have two conditions A and B, and this event:

Conditions: A is true B is true Trigger once Actions: Change scene color
Now some frames:

  • Frame 1: A false, B false >> No action (because A and B are not met)
  • Frame 2: A true , B true > > Actions run (first time A and B are met)
  • Frame 3: A true , B true > > No action (A and B is true but not for the first time, so Trigger once is false)
  • Frame 4: A true , B true > > No action (not the first time, so Trigger once is false)
  • Frame 5: A false, B true > > No action (A is false)
  • Frame 6: A true , B true > > Actions run (here is the trick, if only one condition is false and true again, it is the first time that all the conditions are true for the first time, so the Trigger once is true)
  • Frame 7: A true , B true > > No action (not the first time, so Trigger once is false)
  • Frame 8: A false, B true > > No action (A is false)
  • Frame 9: A false, B false >> No action (A and B is false)
  • Frame 10: A true , B false >> No action (B is false)
  • Frame 11: A true , B true >> Actions run (all the conditions are true for the first time)

If the list is tedious to read, it just says: If only one of the conditions is false and then true again, the Trigger once will be true, because it is the first time that all the conditions are true for the first time, after that at least one of them was false.

That is the reason that moving out and in (holding left click), makes the event to run again, the condition “Cursor over sprite” was false and then true again :wink:
How to fix it? The event should run only once per click, the “Cursor is over sprite” has nothing to do here, so your event should be:

Conditions: Left button click Trigger once Actions: No actions
Of course you have to add the “Cursor is over sprite” somewhere, just add a sub-event with this condition:

[code]Conditions: Left button click
Trigger once
Actions: No actions

    // Sub-event
    Conditions: Cursor is over sprite
    Actions: Your actions go here[/code]

So GD will read: “Left click is pressed for the first time?”, “if so, then, is the cursor over the sprite?”, “if true run the actions” :smiley:

I only understood the frame explanation partially. But the overall rule should be ’ don’t use multiple conditions when using trigger once ’ ?

And nesting them like this always would be a safe solution ?

[code]Condition : A is true.
Trigger Once

Sub-event Condition : B is true.
Trigger Once

Sub-Sub-event Condition : C is true.
Trigger Once[/code]

How about using an object variable?

Touch or left mouse button is down
The cursor/touch is on object
Variable clicked of object = 0

Do something
Do = 1 to variable clicked of object

And to reset the object variable so it can be clicked again:

Mouse button is released
Variable clicked of object = 1

Do = 0 to variable clicked of object[/code]

In case you have more instance of the same object to click, you might need to use the “For each object” event to reset the variable of all if needed, when needed.

Maybe it could be a rule for events activated by the user, for example an event to use an active skill, because the only trigger is the key/button of the skill, the others are conditions to check if you can activate the skill:

[code]Conditions: Button / Key to activate skill pressed
Trigger once
Actions: No actions

    Conditions: Other conditions to activate the skill (mana, distance, etc.)
    Actions: Activate the skill[/code]

If you put all the conditions together (key/button + other conditions), then the user can hold the activation button and wait for the other conditions to be met, and the skill will be activated automatically. Maybe you want this effect in your game, maybe not :neutral_face:

Where all the conditions can be used together with a Trigger once safely is (following the skills example) on passive skills, these don’t need the user to activate them, but are activated automatically when all the conditions are true:

Conditions: Mana is > 10 HP is < 10 % Trigger once Actions: Activate Emergency Nanobots (do + 25 % to player HP recovery rate)
This skill will be activated just one time at low HP, increasing the regeneration rate. Then if HP is > 10 % the conditions are false and you should remove the buff, finally if HP is < 10 % again the Trigger once is true and the skill will be activated one more time.
The same for the Mana, if this skill is active but the user uses all the Mana he/she has, the buff should be removed. The skill will be activated automatically if the Mana is > 10 in a future.

To complete this example, deactivating (remove buff) of this passive skill can be done with this:

Conditions: Mana is <= 10 OR HP is >= 10 % Trigger once Actions: Deactivate Emergency Nanobots (do - 20 % to player HP recovery rate)
The buff will be removed the first time that any of the two conditions for the skill turns false… I have not tested it…
Instead - 20 % (not 25% because a percentage magic, in case you don’t know why), a better approach is to subtract 25% of player base recovery.

The same possible frame problem might be causing something else now. There are two click functions one each for with left and right click for the same sprite. When i click both of them together now, for a few frames, no clicks get triggered.

It seems highly possible that some other pattern got retained similar to the frame issue example you mentioned earlier.

It’s not gamebreaking for now but it is certainly annoying and could annoy and confuse players a bit too. :confused:

How the events look like?

Same conditions for the right click as well.

Not sure about the problem or what do you want to do, please check this example, and let me know if it has that problem :slight_smile: (12.8 KB)

Thanks. The issue is solved now. This specific part of the problem was not due to gdevelop, i figured. It was due to the mouse gestures i had in firefox. Due to my suspicion that it was the cause, i turned it off and it works fine now.

The issue happens only when Rocker Gestures are in-use when using browsers with Mouse Gestures enabled.

But if there is a way to make it work even with rocker gestures in any browser, it would be even better eventhough it is not a the problem with gdevelop. Would be more compatibility for the game made to run with man browser add-ons.