Monitors & displays

Monitor clock

Shows the in-game time in big letters on a monitor, updated every second.

Likes
0
Views
0
In-game installs
0

Uses

  • monitor

Licence

MIT

startup.lua 858 bytes Raw
1-- A clock on a monitor. The time is Minecraft's: a day lasts 20 minutes.
2
3local monitor = peripheral.find("monitor")
4if not monitor then
5 error("Attach a monitor to the computer", 0)
6end
7
8monitor.setTextScale(2)
9
10local function centre(y, text, colour)
11 local w = monitor.getSize()
12 monitor.setCursorPos(math.floor((w - #text) / 2) + 1, y)
13 monitor.setTextColour(colour)
14 monitor.write(text)
15end
16
17print("Showing the time on the monitor. Hold Ctrl+T to stop.")
18while true do
19 local time = os.time()
20 local night = time < 6 or time >= 19
21 monitor.setBackgroundColour(night and colours.blue or colours.lightBlue)
22 monitor.clear()
23 local _, h = monitor.getSize()
24 centre(math.floor(h / 2), textutils.formatTime(time, true), colours.white)
25 centre(math.floor(h / 2) + 1, "Day " .. os.day(), night and colours.lightGrey or colours.blue)
26 sleep(1)
27end

Install in your world

wget run https://ccbin.dev/i/ujtgACws
wget https://ccbin.dev/raw/ujtgACws startup.lua
Embed on your site
<iframe src="https://ccbin.dev/ujtgACws/embed" width="800" height="520" style="border:0" loading="lazy" allow="autoplay" title="Monitor clock on ccbin.dev"></iframe>

Sites that understand oEmbed, such as Discord and many forums, make the embed from the program's link.

Shows the in-game time in big letters on a monitor, updated every second.

This is one of the examples in the Workbench. Run it here, or open it in the Workbench to change it.

Comments

No comments yet.

Sign in to comment.