Jump to content




Time Updating With Menu


  • You cannot reply to this topic
3 replies to this topic

#1 mrdawgza

  • Members
  • 110 posts
  • LocationSouth Africa

Posted 02 November 2013 - 12:23 PM

Hello, I'm back again... :P

I have on my OS, a desktop, and on this desktop a menu bar, on this menu bar I want the time to update, I've gotten it to show
the time, and it updates whenever I click a button, but how can I get it to read for a button click and update the time at the same time?

Code (Extracted from desktop program):
local function bar()
term.setBackgroundColor(2)
term.setTextColor(1)
term.setCursorPos(1,1)
term.clearLine()
term.setCursorPos(1,1)
local time = os.time()
time = textutils.formatTime(time, false)
print("[Menu] | "..user.getCurrent().." | "..time)
term.setCursorPos(47,1)
print(ver)
term.setCursorPos(50,18)
print("[<")
end

Thanks in advance, most helpful reply/replies will get credit.

#2 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 02 November 2013 - 02:55 PM

My guess is you are using an event function or something to check if a button has been clicked right?
So the best thing todo would be to have an timer that updates every second or so and then restart it every time.
local updateTimer = os.startTimer(.8)
while true do
   --# Your drawing stuff here so it's drawn before waiting for events
    local evt, p1 = os.pullEvent()
        if evt == "timer" then
            if p1 == updateTimer then
                updateTimer = os.startTimer(.8)
            end
        --# Other events etc.
        end
end

Hope this was of any use. ;)

#3 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 02 November 2013 - 06:12 PM

View PostHellkid98, on 02 November 2013 - 02:55 PM, said:

.8
Nah, 0.8666666 or 1200/1440. A Minecraft day consists of 24000 0.05 second long ticks, so it's 20 minutes overall. 1440 Minecraft minutes go by in 1200 IRL seconds, so 1 Minecraft minute is 0.86 IRL second.

#4 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 03 November 2013 - 10:31 AM

View PostLBPHacker, on 02 November 2013 - 06:12 PM, said:

View PostHellkid98, on 02 November 2013 - 02:55 PM, said:

.8
Nah, 0.8666666 or 1200/1440. A Minecraft day consists of 24000 0.05 second long ticks, so it's 20 minutes overall. 1440 Minecraft minutes go by in 1200 IRL seconds, so 1 Minecraft minute is 0.86 IRL second.
Well is those milliseconds so important? :P
This is just so the screen updates, It doesn't affect the time.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users