Is there a way to Use State Once after a button click?

Example of it:

I press and hold Left Mouse Button - Attack State

Attack State: Does the animation, hitbox for attack beside the player.

After the animation is done attacking. Attack State would no longer function and would stay at any other state(prefer the previous state before Attack State) than Attack even if the Left mouse button is still being held down.

If I let go Mouse Button then you can do Attack State once more.

I can’t seem to grasp and interpret it on Event system of GDevelop…

Just add a “Trigger once” condition to the left mouse button click:

Conditions: Left mouse button pressed Trigger once Actions: None
This event will run once every time left mouse button is pressed, because the only condition aside Trigger once is the Left button press.

So if you do it:

[code]Conditions: Left mouse button pressed
Trigger once
Actions: None

    Conditions: Player is able to attack (animation different than attack, or is idle, etc.)
    Actions: Do = Attack to animation of Player

[/code]
The parent event will run once on every left click, then the sub-event will run and the player will attack if he is able to do it. The trick is that the sub-event will run only after the parent event runs, so the event to switch to the attack animation will be tested only once for every left click (parent event conditions) :wink:

If you put all the conditions together:

Conditions: Left mouse button pressed Player is able to attack (animation different than attack, or is idle, etc.) Trigger once Actions: Do = Attack to animation of Player
Here, the Trigger once will be true if you:
*Release the left click and press it again while the player is able to attack (as you want)
*Player is not able to attack and then is able to attack again, while the click is pressed (not what you want)
Because the Trigger once is true for the first time all the others conditions are true, after at least one of them was false, I hope it makes sense :slight_smile:

Every event is a while loop

Thanks for the suggestion Lizard and Razor. You’re the only ones here super active these days :smiley:

Wow! I haven’t tried that “Trigger” property yet, need to do some research. :laughing:

Good thing these guys are here to help. Credits should be duly given.

Not sure if this is helpful but in a tutorial I read somewhere (not GDevelop-related), if you’re planning on doing a melee attack, you could use a bullet system with a timer to limit the attack to per N second(s) plus you could also specify the reach of your melee attack by shortening or lengthening the distance your bullet travels. That’s how I understand your case at least, not sure if I got it right though. :slight_smile:

Thanks for the suggestion. Might do that after I’m done building the game and onto polishing it.