Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0

Need a time function program


Hello, (I don't speak english very well, sorry in advance for errors)

I need a program to controll an iron with the in-game time.

But i d'ont know how to ask to the computer the in-game time,

someone can build a simple program to turn on redstone signal at 6AM, and turn it off at 8PM ?

I need the program will be easy to understand, and esay ton configure, annotations are good for this

Thank you in advance, bye !

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

I made you a 'simple' program that does what you ask. Create a file in the /home dir of your computer called 'timer.lua' with the code below as the file contents and save it.

-- # Lua timer for OC forum member
local sides = require 'sides'
local thread = require 'thread'
local component = require 'component'

local setOutput = component.redstone.setOutput
local time
local side = ...

-- # set redstone output to back by default
if not side or not sides[side] then
  side = 'back'

local proc = thread.create(function()

    while true do
      time = os.date('*t')

      if time.hour >= 6 and time.hour < 20 then
        setOutput(sides[side], 15)
      elseif time.hour < 6 or time.hour >= 20 then
        setOutput(sides[side], 0)

      os.sleep(10) -- # update every 10 seconds

proc:detach() -- # background this timer after start

Type edit .shrc in the command prompt and add the line timer.lua side and save the file

Note: replace side above with a valid side string like 'back' or 'south' etc.. and restart the computer or execute the program with timer.lua side like in the .shrc file.

The .shrc file will execute this program on startup for you whenever the computer restart from a shutdown or a crash. Cheers

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.