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

Need a time function program

Question

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 !

Share this post


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'
end

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)
      end

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

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

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