Minecraft – Switch between two different commands when block is activated

minecraft-bedrock-editionminecraft-commands

Basically, I'm trying to make a piston door that is activated by a lever (and an elevator), and what I want is to be able to switch on a lever, which will set a red stone block behind the pistons, then when it's switched off, to summon air behind them.

However the best I could get was a repeat one with the red stone command attached to a chain with the air one and it created some spooky demonic piston doors (the red stone block was flashing while being reset so fast)

So like is there a way that I can set the pistons to activate (or the redstone block to be set) when the lever is turned on, and to replace it with air when it is switched off? I have been having trouble trying to find anything that is remotely close to what I'm trying to do for info. Hopefully I can get some help here, thanks!

Best Answer

Ah, this requires some help from our friend, the NOT gate. NOT gates will turn on when the lever is off... and turn off when the lever is on. Basically, you should build something like this:

enter image description here

And from the back:

enter image description here

The command block on the far left should contain the command

/setblock * * * minecraft:redstone_block

And the one on the far right:

/setblock * * * minecraft:air

Replace the * * * in both commands with the coordinates of where the redstone block should be placed.

Hope this helps!