-1

I created 3 command blocks that are always on repeat, but the problem is I don't have access to the command blocks doing the commands once the command has started. Is there a way for the command to be done for 15sec (for example) and then stop the command from being executed regardless of any other conditions?

I tried to use lever with redstone but the result was not exactly what I was looking for. The start is perfect but the ending can give me extremely different results based on how long the command was active for since I don't have access to the command block or lever.

Currently this is what I have: When the lever is activated, do the command until the lever is deactivated.

3
  • Only cos I am on break atm and don't have the time to post a proper answer: set up a "t-flip-flip" with a "hopper timer"
    – Ben
    Commented May 30, 2023 at 2:39
  • @Ben Can you give me links that explain t-flip-flip and hopper-timer?
    – GroxDots
    Commented May 30, 2023 at 13:20
  • T-Flip-Flop and Hopper Clock
    – Ben
    Commented May 30, 2023 at 22:32

1 Answer 1

1

As with many things that need a timer, you have multiple options. The easiest in this case is probably a scoreboard timer.

For this, you'll need to set up a dummy scoreboard:

scoreboard objectives add timer dummy

Now, you can use a fake player to store the current duration that the command has been running for, by counting up the fake players score by 1 every tick. Next you can check the score using execute if score and only run whatever command you want to run if the score is below the maximum duration (in this case it's 15 seconds * 20 ticks per second = 300).

scoreboard players add #duration timer 1
execute if score #duration timer matches ..300 run <your command>

and then to make the command run again, set the #duration timer score to 0.

6
  • It counts the number but it does not the command at all. I have an orange block with 2 purple ones.
    – GroxDots
    Commented May 30, 2023 at 19:00
  • "does not the command" you mean it doesn't execute the command? And why are you using an impulse commandblock if you want a command to run repeatedly for 15 seconds instead of a repeating commandblock? Maybe you should tell us the commands you actually want to run for us to be able to help you better.
    – Plagiatus
    Commented May 31, 2023 at 6:49
  • the orange command is being executed normally along with the first purple block which does this command (scoreboard players add #duration timer 1) but the second purple block and the main command does not execute. execute if score #duration timer matches ..300 run <your command>
    – GroxDots
    Commented Jun 1, 2023 at 1:44
  • @GroxDots you need to replace <your command> with whatever command you want to run. You should have a setup like this (all unconditional and always active; as many green ones as you need to run commands) where the first (blue) command is the scoreboard players add and the green one(s) are the execute if score .... run <your command> commands.
    – Plagiatus
    Commented Jun 1, 2023 at 7:44
  • How many are for my command? Because I need only one if it is strictly for my command.
    – GroxDots
    Commented Jun 2, 2023 at 22:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .