Using - execute command, how do I check if a block is one of multiple possibilities?

[BACK]
Using - execute command, how do I check if a block is one of multiple possibilities?
Posted On: April 8, 2024

Using an /execute command, I want to check if a certain block is, for example, either oak_fence, OR iron_bars.


However, in my specific case, I can't just use two command blocks to check for either one separately. I tried doing so, like this:.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ oak_fence run tag @s remove tagA.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ iron_bars run tag @s remove tagA.


Note: I set both command blocks to "Repeat", "Unconditional", and "Always active".


The result is not what I expected, because:.


if the block is oak_fence, the tag should be left on, however the second command removes it.


if the block is iron_bars, the tag should be left on, however the first command removes it.


What I need is to check, in a single command, for the tag to be removed only when the block is neither oak_fence OR iron_bars.


A possible solution I've thought of, but haven't tested yet, could be: setting up another 2 tags, check_oak_fence and check_iron_bars, which are given to players standing on either oak_fence or iron_bars.


/execute as @a[tag=!tagA] at @s if block ~ ~-1 ~ oak_fence run tag @s add check_oak_fence.


/execute as @a[tag=!tagA] at @s if block ~ ~-1 ~ iron_bars run tag @s add check_iron_bars.


And then checking for those 2 tags in the as portion of the /execute command, which apparently does permit an OR gate, like this:.


/execute as @a[tag=!check_oak_fence, tag=!check_iron_bars].


I also tested this question's only answer, modifying it so it checks the same block twice:.


/execute if block ~ ~-1 ~ oak_fence if block ~ ~-1 ~ iron_bars.


But that obviously can't work, because that's an AND gate, meaning it checks if a block is simultaneously two types of block at once, which is impossible, thus it can never return true.


Question from user Gaetano96 at gaming.stackexchange.com.


Answer:

You essentially want:.


not(OF or IB).


which, using De Morgan's law, is equal to:.


(not OF) and (not IB).


Giving that, you should be able to chain the last command you found, but with inverted conditions:.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ oak_fence unless block ~ ~-1 ~ iron_bars run tag @s remove tagA.


Answer from user pinckerman at gaming.stackexchange.com.


[BACK]
Using - execute command, how do I check if a block is one of multiple possibilities?
Posted On: April 8, 2024

Using an /execute command, I want to check if a certain block is, for example, either oak_fence, OR iron_bars.


However, in my specific case, I can't just use two command blocks to check for either one separately. I tried doing so, like this:.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ oak_fence run tag @s remove tagA.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ iron_bars run tag @s remove tagA.


Note: I set both command blocks to "Repeat", "Unconditional", and "Always active".


The result is not what I expected, because:.


if the block is oak_fence, the tag should be left on, however the second command removes it.


if the block is iron_bars, the tag should be left on, however the first command removes it.


What I need is to check, in a single command, for the tag to be removed only when the block is neither oak_fence OR iron_bars.


A possible solution I've thought of, but haven't tested yet, could be: setting up another 2 tags, check_oak_fence and check_iron_bars, which are given to players standing on either oak_fence or iron_bars.


/execute as @a[tag=!tagA] at @s if block ~ ~-1 ~ oak_fence run tag @s add check_oak_fence.


/execute as @a[tag=!tagA] at @s if block ~ ~-1 ~ iron_bars run tag @s add check_iron_bars.


And then checking for those 2 tags in the as portion of the /execute command, which apparently does permit an OR gate, like this:.


/execute as @a[tag=!check_oak_fence, tag=!check_iron_bars].


I also tested this question's only answer, modifying it so it checks the same block twice:.


/execute if block ~ ~-1 ~ oak_fence if block ~ ~-1 ~ iron_bars.


But that obviously can't work, because that's an AND gate, meaning it checks if a block is simultaneously two types of block at once, which is impossible, thus it can never return true.


Question from user Gaetano96 at gaming.stackexchange.com.


Answer:

You essentially want:.


not(OF or IB).


which, using De Morgan's law, is equal to:.


(not OF) and (not IB).


Giving that, you should be able to chain the last command you found, but with inverted conditions:.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ oak_fence unless block ~ ~-1 ~ iron_bars run tag @s remove tagA.


Answer from user pinckerman at gaming.stackexchange.com.


[BACK]

Which companions are longterm compatible for recruitment in Baldurs Gate 3? Which companions are longterm compatible for recruitment in Baldurs Gate 3?

Posted On: August 29, 2023
Having just finished my first play-through of BG3, I'm contemplating a replay. One of the things that would make a replay more interesting would be if I could recruit all the companions I failed t...[More]


More questions from an outsider More questions from an outsider

Posted On: October 24, 2023
As I've seen more footage from Baldur's Gate 3 (As an outsider who can't play), I've become curious about a few more things, if people would feel up to answering them for me! . I...[More]


Can you play the entire game solo? Can you play the entire game solo?

Posted On: May 28, 2024
Just curious. It seems like it would be impossible with some of the fights but I wonder if it can be done. Like you just use tav and leave all your companions at camp every day?Question from user glit...[More]


What happens if you play an attack card twice but the targeted enemy dies after its played once? What happens if you play an attack card twice but the targeted enemy dies after its played once?

Posted On: December 17, 2023
Let's say I'm facing a group of two enemies. I play Double Tap which makes it so my next attack is played twice. I then play Anger which does 6 damage and target an enemy that only has 6hp. Wh...[More]


In Assassins Creed 3, What is the best way to expose a ships powder stores? In Assassins Creed 3, What is the best way to expose a ships powder stores?

Posted On: April 16, 2023
On some of the ship missions, there is an optional objective of "sink ships by firing on their powder stores". I know how this works broadly - I've shot up some ships and got the spec...[More]


How can you resist him? How can you resist him?

Posted On: October 23, 2025
Question from user Fun-Explanation7233 at BaldursGate3 at reddit.com.Answer:I havent done much with him, but when he drinks your blood I couldnt get him to stop so I died.But I loveed his reaction whe...[More]


What are these green and orange dots on the Soviet Installation map? What are these green and orange dots on the Soviet Installation map?

Posted On: August 22, 2023
I am playing Rise of the Tomb Raider on PC. When I press the TAB key, I get the map, and I see (red arrow highlighted) green/orange dots and dotted lines. What do they mean? How can these be use...[More]


What does a checkmark in the Monster List mean? What does a checkmark in the Monster List mean?

Posted On: November 27, 2023
When looking at the Monster List, what does it mean when a monster has a green checkmark next to them? Question from user Stevoisiak at stackexchange. Answer: A green checkmark means you have...[More]


Can you drop bottlecaps in Fallout 4? Can you drop bottlecaps in Fallout 4?

Posted On: July 15, 2023
I've found a few lonely bottlecaps out on the wastelands, but I was wondering if you can get them out of your inventory onto a table to make, say, a bottlecap pyramid. As a bonus question I was al...[More]


How do I get the ghillie suit? How do I get the ghillie suit?

Posted On: November 19, 2023
Sometimes while I play Call of Duty Modern Warfare 3 online, I see people with a ghillie suit to help them blend in to their surroundings. How do I get that costume? Question from user Scribblenaut...[More]