3
I am aware of the If and Unless statements but I haven't figured out a way to make conditional lines as in the way it can be done with command blocks.
I am looking to make it where command two will not run unless command one successfully runs, any idea on how to accomplish this?
I am looking to make it where command two will not run unless command one successfully runs, any idea on how to accomplish this?
Create an account or sign in to comment.
9
1
solved
1
Yeah theres a few ways. They all require a 2nd command after the first before running the 2 commands. (Unless it is just detection)
If this is just detection of an entity:
/execute as <entity> run tag @s add DoThis
Then the 2 commands + removing the tag:
/execute as <entity>[tag=DoThis] run command1
/execute as <entity>[tag=DoThis] run command2
After those 2 remove the tag (put in the command after those 2 commands, as functions go from top-bottom):
/execute as <entity>[tag=DoThis] run tag @s remove DoThis
Without further elaboration, I cannot give you a proper guide.
If this is just detection of an entity:
/execute as <entity> run tag @s add DoThis
Then the 2 commands + removing the tag:
/execute as <entity>[tag=DoThis] run command1
/execute as <entity>[tag=DoThis] run command2
After those 2 remove the tag (put in the command after those 2 commands, as functions go from top-bottom):
/execute as <entity>[tag=DoThis] run tag @s remove DoThis
Without further elaboration, I cannot give you a proper guide.
1
The depends a little bit on the condition you're trying to archive.
As a tip: When running a command via "execute as", if a @ selector (which can also be filtered by nbt tags) returns no result, the command won't be executed.
As a tip: When running a command via "execute as", if a @ selector (which can also be filtered by nbt tags) returns no result, the command won't be executed.
2
You can change the second command block's state to "conditional", "chain" mode and "always active", then it will only execute its command if the command block pointing to it (the command block with the first command) has executed its command successfully.
2
Oop, I knew that this question was for datapacks. I guess I didn't specify, oops.
1
Oh okay, unfortunately I don't know anything about data packs :/
2
yep- you beat me to it! If you want to take a Redstone signal from the first command then you can use a comparator going out of the block and into a repeater.
1
Yeah, that works but it makes large command block structures slow because the comparator has 1 redstone tick delay. Chained command blocks execute their command in the same tick as the command block that activated them.
I think another problem with comparators is that you need to reset them or the command block they're getting their signal from after the command has been executed successfully.
I think another problem with comparators is that you need to reset them or the command block they're getting their signal from after the command has been executed successfully.
2
Fair point. You could also put a /setblock x y z redstone_block and a /setblock x y z air if you really wanted to.