How do I assign 1 button to two actions?

I’m making a fnaf fan game and I want the doors to work right, so I want to assign 1 shoulder button (LB = Left door) (RB = Right door) to two actions, open and close. press once to open press once to close.

Above image is my current code for the doors. Let me know if I have to change it to get my desired result.

1 Like

If open and close are the only 2 animations you have for the doors, then you can use the following to switch between them:

The mod function returns the remainder when the first number is divided by the second.

Found it, anyway thanks for the help, gonna use this and see what happens.

Did I do it right? Cause when I click the same button again it does not play the opening animation.

No, you have ...animation::index()+ 0, 1)

You want ...animation::index()+ 1, 2)

You want to increase the animation number, then divide it by the number of animations (2 in this case). Increasing it by 0 does not change the animation number.

Right I did that, was gonna ask how to fix this. doors test 1

It works after the door open animation plays in the beginning, obviously thats not good looking.

That’s because you pause the animation at the beginning of the scene.

To fix this, instead of pausing the animations at the beginning, set the current frame to how ever many frames are in the animation (you’ll have to manually count the number of frames and put that in, there are no expressions for it :expressionless: )

Ok, thanks for the help.

Or let the animations play out and fade the scene in once the animations have finished. That just needs a black sprite covering the whole screen, and its opacity changed or tweened to 0 once the door animations are done.

oh ok I’ll see about that.

wait how do I set the current frame? also i mistaken the animation that plays first is the closing one. so the loading thing wouldn’t work.

Click “Add action”, select the door sprite, and search for “current frame”.

And I use the “= set to” modifications sign right?

Yes. If you change the number of animation frames, then the number you assign it to will have to change. There’s no expression that could be for that, unfortunately.

1 Like

It’s a lot easier to use an object boolean, and if the door is open, then the animation is open, and the colission mask is different, or else, the player is only stopped if the boolean is false.
A button could easily switch on or off the boolean.

And welcome to the community, Rosanna. Don’t worry. The main way to learn in GDevelop is through bad experience.

Checking the door animation name is just as simple, and there’s no need to faff around with toggling boolean variables.

You could do that, but you can show a special door object as closed when open, like an illusion, if it’s a boolean, which just gives the dev a lot of extra power over level design.

Furthermore, if it’s a group, then some doorswon’t work if their animation is capitalized wrong or spelled wrong, while the boolean is just one thing to juggle.

Yep. Or you can use another sprite object, or another animation with different collision masks. Incorrect spelling or capiitalisation goes for variable names too.

The thing is, there’s often more than one way to code an effect. Usually either way is fine, and normally either way is easy to implement. I provided a solution keeping with the way OP had originally coded it. Minimal changes to get the desired effect.