[SOLVED] Activate/Deactivate a button with a player or a clone

Hello everybody! :smiley:

Here’s the situation:
In a platform game, I have a button on the floor that is being activated when the player steps on it, but the button has to go back to the original position when the player goes away from the button.
The idea is that I want to force the player to have the ability to clone themself to be able to leave “a weight” on the button and keep it activated.

But here’s the problem:
Pretty much everything works fine, except when the clone is not there.
I used the “is on layer” condition, but it only works when the clone is on the scene, no matter what.
(I basically create and delete the clone with the ability).
So if the clone is there, the button goes back up when neither the player or the clone steps on it, but if the clone is not there, it stays down when the player goes away from the button.
As soon as I create the clone (away from the button), the button goes back up.
So it really feels like my inverted condition “is on layer” is not triggered at all.

Do you guys have any idea how I can fix that?

Thank you very much in advance! :smiley:

On the screenshot, the “toggle” is a trigger zone I put on the top of the button so the player can only activate it from the top.

  1. Do you need to have those layer checks? They seem unnecessary.

  2. You should really only have 2 events: one to activate the button and one to deactivate the button.

Your first condition with the OR seems fine. You don’t need those layer checks, unless you are moving the clone and not deleting it (which I doubt you are doing). You don’t need the AND either. You should just have the event with the inverted player and playerclone collisions.

I don’t know why it would be necessary to check if the clone exists, but if it is necessary, then use the object count condition, and not checking if it exists on a lter.

Thank you for your answer :smiley:

Well, to be fair, I don’t know. I’m pretty new on Gdevelop (less than 2 weeks), so I probably did a lot of unnecessary things so far XD

I already tried having only the inverted collisions conditions, like that (if it’s what you mean):

But I end up with the same problem. If the clone is not there, the button does not go back up.
It feels like the code is looking for the clone, and seeing that it does not exist, it can’t accept the inverted collision condition as being true. If you know what I mean.
That’s the reason why I tried the “is on layer” condition. But it did not work neither.

Sometimes if an inverted condition doesn’t work, a NOT condition will work. So give that a try and see if it helps. Search for NOT in conditions.

Looking at your events though it really looks like you’re telling the button not to go back up unless both the clone and the player is not in collision with it. So the inversion seems to be working fine here. Because as you explain, it won’t go back up unless the clone is present too.

So probably what you can do is if the player is in collision with the button set the button bool to true and if it’s not set the bool to false. Separate event just like that for the clone. Separate events for the button if bool is true use this animation. If false use that animation.

Thank you for your answer as well!

Unfortunately, it doesn’t seem to work.

Just edited based on your pics

Oh, it works! :smiley:
I tried to use the NOT on both Player and PlayerClone. First together, then separately.
I did not work.
But after my last answer, I tried the NOT only on PlayerClone, keeping the inverted condition only for Player, like that:

I can’t really understand why it works that way, to be honest, but at least it works x)
(not knowing why is clearly annoying, but I’ll figure that out for sure at some point :stuck_out_tongue: )

Thank you very much for your help :D.

To be honest I don’t understand why the NOT works sometimes either haha When you figure it out let me know…

I will, no problem :stuck_out_tongue:
Thank you very much again, and have a good day :smiley: