TransWikia.com

How can I run a command if one or more conditions in /execute are satisfied?

Arqade Asked by user246332 on December 22, 2020

In Minecraft 1.16.1, I’m trying to make a system thats detects when one of several fake players doesnt have a specific score.
Here is my first attempt:

execute unless score sticks_have page-2 matches 2.. unless score plank_have page-2 matches 1.. run ...

After trying this, I realized that all scores need to be in the correct range before it runs the command! But I want it to run the command when any of the scores are in range.

I thought of using the following command, but it doesn’t detect fake players:

execute unless entity @a[scores={sticks_have=2..,plank_have=1..}] run...

I know I can use multiple command blocks, but I would rather not, just do I can conserve space.

What can I do?

2 Answers

Unfortunately, combining if and unless arguments using OR is hard to achieve. Most of the time, you'll have to have one command per possibility. When you have many different possibilities, try using functions1 for each possibility.

1If you are using older versions of Minecraft, you'll need to find the correct version of the page in the history.

A similar problem exists when trying to combine target selector arguments using OR. See the other question here.

Correct answer by ExpertCoder14 on December 22, 2020

In your case you only need two commands, not one per case, by using AND and inverting the result. I assume here that you want to trigger something if either page-2 of sticks_have is in 2.. or page-2 of plank_have is in 1.. (weird naming scheme BTW).

/execute unless score sticks_have page-2 matches 2.. unless score plank_have page-2 matches 1.. run tag @s neither
/execute unless entity @s[tag=neither] run …

You can use anything other than a tag as well, of course, as long as you can check the inverted case.

Here is the logic table of this:

┌─┬─┬──┬──┬─────┬────────┬───┐
│s│p│!s│!p│!s&!p│!(!s&!p)│s|p│
├─┼─┼──┼──┼─────┼────────┼───┤
│0│0│ 1│ 1│  1  │    0   │ 0 │
│0│1│ 1│ 0│  0  │    1   │ 1 │
│1│0│ 0│ 1│  0  │    1   │ 1 │
│1│1│ 0│ 0│  0  │    1   │ 1 │
└─┴─┴──┴──┴─────┴────────┴───┘

Answered by Fabian Röling on December 22, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP