How to set Command Block(s) to test for a particular time and output a message?

How to set Command Block(s) to test for a particular time and output a message? - Set of blood test vials arranged on pink table

I simply want one command block to test for the time of day or night (e.g. time = 18000) and output a message in the chat to everyone if that time returns true.

I was trying a simple set-up with two command blocks and a comparator in the middle, but I'm a beginner and am obviously missing the correct syntax (especially to test for a particular time of day, and if true, then trigger the say "message" block).

ETA: Kudos to @Ben for the Daylight Sensor/Redstone idea, but I'd really prefer a Command Block solution for the above, since my plan is to output several messages during the day and night cycle at very specific times in the world. Thanks.



Best Answer

An easier option might be to use a daylight sensor. Set it up with a string of Redstone and see how far the signal is when you set the time (/time set 18000).

Then, you can do something tricky like this to invert the signal:

enter image description here

What this will do, is when the signal from the daylight sensor dies, the Redstone torch will be turned on, firing up the command block.

enter image description here




Pictures about "How to set Command Block(s) to test for a particular time and output a message?"

How to set Command Block(s) to test for a particular time and output a message? - Black Ring Bell Alarm Clock
How to set Command Block(s) to test for a particular time and output a message? - From above of anonymous barefoot boy and girl in casual clothes sitting on floor carpet and playing with wooden blocks of jenga tower game
How to set Command Block(s) to test for a particular time and output a message? - High angle collection of various trial lenses and frame placed in red holder in ophthalmology clinic



How do you set a timer on a command block?

Give yourself a Command Block by opening the chat box and entering \u201c/give [your username] minecraft:command_block\u201d Turn on Creative Mode by typing \u201c/gamemode c\u201d in your chat box. Place the Command Block where you want it.

How do you make a command block give you a message?

This solution only works on Minecraft 1.9 and above!
  • Repeat Command Block: /scoreboard players add @e[score_time_min=1] time 1.
  • Chain Command Block 1: Put your delayed command here. ...
  • Chain Command Block 2: /scoreboard players set @e[score_time_min={delay}] time 0.




  • Minecraft Title Command Tutorial. Learn How To Use All Title Commands In This Minecraft Video!




    More answers regarding how to set Command Block(s) to test for a particular time and output a message?

    Answer 2

    So this method isn't by any means easy, but it's no worse than some of the other command block solutions I've come up with in the past.

    First things first, you need a 20Hz fill clock. How to make one isn't exactly within the scope of this question.

    Next, you'll need a scoreboard objective to hold the current day time:

    /scoreboard objectives add DayTime dummy
    

    You'll also need an empty player that will keep track of day time:

    /scoreboard players set #TimePlayer DayTime 0
    

    The first command block to be triggered by the fill clock should query the time of day from the game:

    time query daytime
    

    We need to redirect the result of command block to the scoreboard objective we set up earlier. Turn off the fill clock, stand directly on the command block, and enter this command:

    /stats block ~ ~-1 ~ set QueryResult #TimePlayer DayTime
    

    Now, you'll need a pair of command blocks for each time you want to test for. The first will do the actual test, and the range values on it should be one below and one above the time that you want to test for. For example, if you wanted to test if it's noon (6000), the command would be this:

    scoreboard players test #TimePlayer DayTime 5999 6001
    

    Use a comparator to output the result to the second command block, and get it to perform whatever action you want, for instance, telling everyone that it's noon:

    say It's Noon!
    

    Answer 3

    A command block with the command

    /time query 18000

    Would test for the time 18000 and be able to send a comparator output.

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Alena Shekhovtcova, NEOSiAM 2021, Ketut Subiyanto, Ksenia Chernaya