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

Basic time display (ingame time and RL time)

Question

Heyo dear OC community!

 

I recently discovered this mod and it fascinates me. So many possibilities, it's incredible!

However I totally lack the knowledge of lua (etc.) and can't really figure out how the simplest things work in here.

 

I didn't want to dig deep into this mod on my first attempt so all I want for now is a simple screen showing the current ingame and/or real-life time. Unfortunately I already failed there. Horribly. I spent many hours searching the internet, watching the tutorial videos, reading the wiki and the ingame manual and I finally found my way to this forum.

 

I hope you guys can help me with a basic program and maybe explain it a bit so I can learn from it :)

 

 

Thanks in advance.

 

Aeon

Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Hey there! Welcome to the OC forums. It's a bit of a ghost town at times, but I'm usually here with a few others to answer questions.

 

The program you're looking for would be as follows:

local os = require("os") --requires the os library
local term = require("term") --requires the term library

while true do --runs forever
  term.clear() --clears the screen
  print(os.date("Current time is: %X%p")) --prints the current ingame time.
  os.sleep(1) --makes the program wait for a second
end

The os and term libraries are part of lua. Feel free to look them up, they are basically the same as the official ones, with a few tweaks. I also explained the program using comments in lua, which are pieces of code that the executor ignores when running the code, they start with --.

 

In case you were wondering, the %X%p part of the string in the print is important, it tells os.date what format to put the date in, more info on that here:

 

http://www.lua.org/pil/22.1.html

 

 

Any more questions? Ask away. If you'd like some plug and play programs that already work and exist, check out the program showcase of the forums. I have a few programs there myself.

Link to post
Share on other sites
  • 0

Thanks for the program and explanation, it helped me a lot. I'm studying automation engineering at a university in Austria and I know C# so I got some knowledge how to interpret/understand code. My problem is that I don't know how lua works, how lua's code syntax, libraries, methods, variables, etc etc look and work like.

 

Is there a list of all pre-defined methods of those libraries somewhere?

 

I'll look into those program collection on forums but at the moment they are way over the top of my needs ^^

 

Cheers,

Aeon

Link to post
Share on other sites
  • 0

Real-life time is a little more tricky than in-game time, because OpenComputers/OpenOS has no built-in APIs for that. The most reliable way would probably be to store the real-life time for Day 1, 00:00 in-game time, and then to calculate the current real-life time based on this epoch and the current in-game time. If you want to know the exact time scale of in-game to real-life time, look it up on Minecraft Wiki. :)

Link to post
Share on other sites
  • 0

Real-life time is a little more tricky than in-game time, because OpenComputers/OpenOS has no built-in APIs for that. The most reliable way would probably be to store the real-life time for Day 1, 00:00 in-game time, and then to calculate the current real-life time based on this epoch and the current in-game time. If you want to know the exact time scale of in-game to real-life time, look it up on Minecraft Wiki. :)

 

I bet you could also retrieve the real world time from an internet website using http, although I wouldn't know of one.

Link to post
Share on other sites
  • 0

So I managed to get a simple program running and I quite like it.

local os = require("os")
local term = require("term")
local component = require("component")

local i = 0

component.gpu.setResolution(10,4) --fitting my current 5x3 tier1 display

while true do
  term.clear()
  if i == 0 then --simulating flashing colon
    print(os.date(" %I:%M %p")
    i = 1
  else
    print(os.date(" %I %M %p")
    i = 0
  end
end

I would now like to implement a rain indicator. For that I thought I'll use the rain-sensor from a ProjectRed and connect the redstone signal to the OC-Case. I assume I'll need a redstone card and the Redstone I/O to receive the redstone input for that right? And how do i check the redstone signal in the code?

 

Output should be something like that:

<time>

<weather:state>

 

Example:

6:30 AM

Weather: sunny

 

 

Cheers,

Aeon

Link to post
Share on other sites
  • 0

So I managed to get a simple program running and I quite like it.

local os = require("os")
local term = require("term")
local component = require("component")

local i = 0

component.gpu.setResolution(10,4) --fitting my current 5x3 tier1 display

while true do
  term.clear()
  if i == 0 then --simulating flashing colon
    print(os.date(" %I:%M %p")
    i = 1
  else
    print(os.date(" %I %M %p")
    i = 0
  end
end

I would now like to implement a rain indicator. For that I thought I'll use the rain-sensor from a ProjectRed and connect the redstone signal to the OC-Case. I assume I'll need a redstone card and the Redstone I/O to receive the redstone input for that right? And how do i check the redstone signal in the code?

 

Output should be something like that:

<time>

<weather:state>

 

Example:

6:30 AM

Weather: sunny

 

 

Cheers,

Aeon

 

You will only need either the redstone card or the redstone io, both give the library you need. Going on your example, here's what it would look like.

    local os = require("os")
    local term = require("term")
    local component = require("component")
    local red = component.redstone
    local sides = require("sides")
     
    local i = 0
     
    component.gpu.setResolution(10,4) --fitting my current 5x3 tier1 display
     
    while true do
      term.clear()
      if i == 0 then --simulating flashing colon
        print(os.date(" %I:%M %p")
        i = 1
      else
        print(os.date(" %I %M %p")
        i = 0
      end
      --check weather
      if(red.getInput(sides.left)>=1) then --if getting a signal from the rain sensor on the right
        print("Weather: Raining")
      else
        print("Weather: Sunny")
      end
    end

This assumes you feed the redstone from the rain sensor into the right side of the computer, you can of course change that to your liking. Directions on the sides library are from the perspective of the computer case, so opposite when looking at it.

 

More on the redstone api here:

 

http://ocdoc.cil.li/component:redstone

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.

Guest
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.

Loading...

×
×
  • Create New...

Important Information

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