(Solved) How do i make the same button show and hide layer?

So i was trying to make a button hide and show a layer but it shows and hides the layer instantly
what should i do?

Think about the logic of the conditions. When you click the button the layer becomes visible, when the layer is visible and the button is not clicked, your other condition executes as well and hides the layer. Thus the second events execute immediately after you clicked the button.

To solve this simply change the second “is clicked” to not inverse. If you wanted to make the “code” smoother and more concise, you can have two sub conditions that check if the layer is visible or not under the condition checking if the button was clicked.

Instead of setting the boolean, you can use the toggle boolean variable action. It toggles the value between true and false and then back to true …

Button clicked – toggle boolean variable
-------boolean=true ----- show layer
-------booleam=false — hide layer

I tried the (not inverse) method , it doesn’t even shows the layer

Thank you very much :smile:
it’s working i always used the Set the boolean method for buttons and it mostly works.
But thank you , you helped me a lot!!

For anyone else who is facing the problem here’s the event

1 Like

You’re welcome. I didn’t think about it earlier but Gdevelop now includes toggle switch objects. They give nice visual feedback as to their state. There’s switches and button designs. They’re also customizable.

I see after experimenting further I realize that this method doesn’t work either due to how fast the conditions are processed. If the layer is hidden and the button is clicked the layer will be shown, but since this happens so fast the button is still technically “clicked” and thus the inverse visibility condition activates as well and hides the layer immediately after the previous frame it was shown. I apologize for not realizing this sooner, I’m glad you were able to solve this using Keith’s solution!

Toggle Switch i gave seen it in but haven’t used it, but i think they will be great for menu UI.

Hey i have one more question if you don’t mind, I have an action marker in game that shows where the player is going to hit etc just like “stardew valley” it is connected to mouse movement in a 3x3 grid but now i want to make it a fixed action marker which is going to be always in front of the player any idea how can i do that? :sweat_smile:

Yeah that is the problem, don’t apologize it’s alright i am still learning so i don’t have much knowledge about gdevelop

I’m not sure what you want. I’m not familiar with stardew valley. How are you moving the character? Mouse, keyboard, pathfinding? Where should the marker be?


Isn’t that the same thing you have already asked about here?:

Yes but i just couldn’t figure it out so asked here… Just need a little explanation about the steps

I am using keyboard (w,a,s,d) the marker should be wherever the player is facing

Like this

Preview of Avalon 7_19_2023 8_35_22 PM