Help with a button,that does two things(Solved)

So I need help on making an overlay that if clicked once it activates one barrier(Lets call this barrier B1) , but if it is clicked twice it activates a second barrier (Lets call this barrier B2) and deactivates B1. But if the overlay is pressed again it activates B1 and deactivates B2. If the overlay is pressed again it activates B2 and deactivates B1. And the so one and so on.
This is probably very confusing so if something doesn’t make sense please tell me.

heres a bad example of what I mean , That I made on scratch.
Screen Recording 2025-03-16 at 11.01.13 AM

I know this is possible with block code .but I don’t know how to make it.

2 Likes

I’ll try to make this, give me a second…

2 Likes

Okay, my explaining skills are horrible but bear with me on this…

You need:
2 barriers, an overlay and a property.

Give the property these settings (you can change the name to whatever you like):


then, go to an overlay and give it these settings:

and then input this in the blocks section:

Then go to the barriers put these settings for one:

And these settings for the other:

The reason the property is called “red barrier” is because i colored one red, you can change it to B1, also make sure either B1 or B2 is not active on game start (If it’s B1, then change the setting in the property to “false”)

2 Likes

Okay wait, for some reason this is not working :[

WHY IS THIS NOT WORKING

1 Like

You could update a counter whenever you click the overlay, and save the value to a property. Then in the code of the overlay write an if state-ment seeing if the number is even or odd. If it’s odd, activate the first button, if even, activate the second one. I guess to make sure, also broadcast a deactivation channel for the opposing button, so only 1 button is active.

2 Likes

You could even use a checker instead of block code to check if it’s 1 then show barrier 1 and hide barrier 2 and if the check fails then show barrier 2 and hide barrier 1

1 Like

Makes sense, you could add on to that for when the second one is correct (ie 2), we reset the counter, so when the click again, 1, it repeats. That’s a good idea.

You don’t need property and block code for this, just switch the two overlays and the channel transmitted to the assigned barriers.

2 Likes

You will need two [button] Overlays and two Barriers:

Settings:

Overlay 1: Transmit on X Channel when pressed, shown when receive on Y Channel, and hide when receive on X Channel, player-scoped.

Overlay 2: Transmit on Y Channel when pressed, shown when receive on X Channel, and hide when receive on Y Channel, player-scoped, not activated when game start[1]

Barrier 1: Player-scoped, not activate when game start, activate when receive on X Channel, deactivate when receive on X Channel.

Barrier 2: Player-scoped, not activate when game start, activate when receive on Y Channel, deactivate when receive on X Channel.


Although you can do it with property+blockcode or checker system, this should be the simplest way possible.

A similar method but on wires:


  1. note that this overlay is not shown at the beginning of the game ↩︎

4 Likes

very good point although I think having one button and doing a check might be easier to keep track of and see what’s happening easier (it’s all personal preference though)

Yeah, but a checker system would require more memory usage than using two overlays.

Edit: Ah, you are right, my bad.

2 overlays use 350 memory while a overlay, checker, property, and counter use 245 memory. If I’m wrong on that then it doesn’t make a huge difference because it’s such a small amount of memory.

1 Like

Sorry of the late response but thank you , your solution worked for me.