Forumskeyboard_arrow_right Minecraft - Java Edition keyboard_arrow_right Data Packs

Create Forum Thread
2

How can you make a conditional command in datapacks?

2 emeralds9 replies115 views
created 12/09/2019 2:42 pm by ManKiind
last reply 12/17/2019 4:32 pm
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?
Posted by avatar
ManKiind
Level 13 : Journeyman Miner
1

comment Login or register to post a reply.

9 replies

1
12/17/2019 4:32 pm
Level 13 : Journeyman Miner
ManKiind
solved
1
12/10/2019 12:35 am
Level 19 : Journeyman Unicorn
HoboMaggot
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.
1
12/09/2019 3:46 pm
Level 28 : Expert Engineer
Chillo
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.
2
12/09/2019 3:11 pm
Level 67 : High Grandmaster Hero
Captain_JEK
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
12/09/2019 7:26 pm
Level 13 : Journeyman Miner
ManKiind
Oop, I knew that this question was for datapacks. I guess I didn't specify, oops.
1
12/10/2019 7:37 am
Level 67 : High Grandmaster Hero
Captain_JEK
Oh okay, unfortunately I don't know anything about data packs :/
2
12/09/2019 3:32 pm
Level 15 : Journeyman Dragonborn
TobySuren
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
12/09/2019 4:00 pm
Level 67 : High Grandmaster Hero
Captain_JEK
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.
2
12/09/2019 4:32 pm
Level 15 : Journeyman Dragonborn
TobySuren
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.
Planet Minecraft Logo

Website

© 2010 - 2020
www.planetminecraft.com

Welcome