2

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.

5

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

  • I don't want to change the time itself. What I'm looking for is when the world reaches a particular time, it will output a message. Though your solution is an interesting idea. Are you suggesting I offset a redstone trail to compensate for an arbitrary amount of time ticks? If that's the case, I'd need thousands of repeaters to pull it off. – cmykev Dec 30 '14 at 2:27
  • @cmykev it sounds like you don't know how a daylight sensor works. Take a look at the wiki article. – MBraedley Dec 30 '14 at 2:40
  • 1
    No, I think you're misunderstanding. This setup will execute a command at the appointed time, if setup correctly. I.e. at 18000, the daylight sensor will emit a signal of a certain strength. This will power the block, and invert the torch. After that point, the signal will get weaker, the block will no longer be powered, the torch will turn on, and the command block will be triggered. – Ben Dec 30 '14 at 2:40
  • aside from the command block i know this set up works as i use it on lamps to turn on at night, the redstone that goes to the block inverts the redstone touch on the other end so during the day the touch is off while at night the touch is on – Memor-X Dec 30 '14 at 2:44
  • @cmykev also, the point I was making about setting the time was only to see what signal strength was at 18000, so you could create this setup the way you wanted to – Ben Dec 30 '14 at 2:58
3

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!
  • This will only work for one day. daytime doesn't reset after 24000 ticks but keeps going. – MrLemon Feb 11 '16 at 9:12
  • @MrLemon: "query - returns the day time (game ticks since midnight), the game time (game ticks since world start), or the day number (matching the value displayed on the debug screen)". That seems to indicate that you are incorrect. – MBraedley Feb 11 '16 at 12:20
  • @MBraedley I thought so too, but I actually tested in while writing this answer. – MrLemon Feb 11 '16 at 12:43
  • with the new command blocks just set the command block to a repeating one and hit the button that says needs redstone... – Epb7304 Sep 12 '16 at 23:30
  • @MrLemon You're thinking of /time query gametime. Timee query daytime results in getting the time of day. – Meowl May 26 at 20:45
1

A command block with the command

/time query 18000

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.