This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mrdawgza's profile picture

Time Updating With Menu

Started by mrdawgza, 02 November 2013 - 11:23 AM
mrdawgza #1
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.
TheOddByte #2
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. ;)/>
LBPHacker #3
Posted 02 November 2013 - 06:12 PM
.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.
TheOddByte #4
Posted 03 November 2013 - 10:31 AM
.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.