CLOCKS

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

NHsports123

New Member
Jul 29, 2019
15
0
0
Mine was a bit different.
Code:
i = 1
while i == 1 do
term.clear()
term.setCursorPos(1,1)
print(textutils.formatTime(os.time(), boolean))
sleep(1)
end

The term.clear and term.setSursorPos just clear the screen and resets the cursor so it always puts the time on the top line.

The sleep is just so that there is a delay between time refreshes, no point having it refresh every tick.

The while i == 1 do
"code"
end

Is just an infinite Do loop. I set the variable i to be 1 at the start, so it is always true and so always loops. You could replace the first 2 lines with 'while true do' and it should still work.
Thank you, this is very helpful. Which would you prefer? The loop or the other one you mentioned where it deletes and redisplays the correct time?[DOUBLEPOST=1364782018][/DOUBLEPOST]
your country is silly, use a 24h clock.
I agree with you. In fact, my phone uses the 24 clock. Alas, if I made a 24 clock in the game, my friend would complain about it haha :p
 

Mikey_R

New Member
Jul 29, 2019
382
0
0
Thank you, this is very helpful. Which would you prefer? The loop or the other one you mentioned where it deletes and redisplays the correct time?

They are both loops, but with the first loop that was suggested the time would just keep filling up the screen and you would get a long list of times and eventually crash the computer (trust me, I tried), so I just improved it by deleting the previous time, resetting the cursor (otherwise the time would just keep going down the screen) and then printing the new time, so it looks like it is updating.

So, I would say it is worth adding in the couple of lines to allow it to clear and then re print the clock as it would look neater. I only put the sleep(1) command in because I'm sure you don't want it to update every tick, so it updates every second instead, just change the number in the brackets to adjust the length of time between refreshes, so sleep(2) refreshes every 2 seconds, sleep(0.5) is every half a second etc.
 

NHsports123

New Member
Jul 29, 2019
15
0
0
They are both loops, but with the first loop that was suggested the time would just keep filling up the screen and you would get a long list of times and eventually crash the computer (trust me, I tried), so I just improved it by deleting the previous time, resetting the cursor (otherwise the time would just keep going down the screen) and then printing the new time, so it looks like it is updating.

So, I would say it is worth adding in the couple of lines to allow it to clear and then re print the clock as it would look neater. I only put the sleep(1) command in because I'm sure you don't want it to update every tick, so it updates every second instead, just change the number in the brackets to adjust the length of time between refreshes, so sleep(2) refreshes every 2 seconds, sleep(0.5) is every half a second etc.
Well how long is each 'tick'? And how about a Minecraft minute? I'd like the clock to display the correct time every minute.
 

Mikey_R

New Member
Jul 29, 2019
382
0
0
Each tick is 0.05 seconds, so it's 20 ticks in a second.

I'll get back to you on the timings needed.

Right, assuming my maths is right, 0.83333... real life seconds = 1 minecraft minute. Of course, that isn't a nice number to try and put into a program, but 0.8 + (1/30) will give you that number exactly.

Now, I won't write the program again, but I can give hints as to how to do it.

Obviously, you need a do loop, so the 'while true do' *code* 'end' should do.

As for the time, you set a variable, say m for minutes and each time the loop goes through you add 1. You then need an IF statement that says, If m = 60 then m = 0 and h = h+1 (assuming h is the hours) That takes h and adds 1. You would then need another IF that says, If h = 13 then change from AM to PM (that should just be text or a symbol).

And that is the basics of the program. Again, if you sleep in a bed it will stop showing the correct time as those ticks you 'slept' for didn't happen.
 

NHsports123

New Member
Jul 29, 2019
15
0
0
Hmmm, I'll try to make the code in the next day or two. So if I sleep, I have to restart the clock?
 

Jay Cee

New Member
Jul 29, 2019
89
0
0
your country is silly, use a 24h clock.
That's just silly. Your country should use a binary clock. That's what we did, but because the Prime Minister had a fear of the number one, we had to adjust all the clocks to make it from just zeros.
 

NHsports123

New Member
Jul 29, 2019
15
0
0
That's just silly. Your country should use a binary clock. That's what we did, but because the Prime Minister had a fear of the number one, we had to adjust all the clocks to make it from just zeros.
Forget Base 2, that's just straight up Base 1, or should I say Base i for imaginary. I'd like to see that! Lol
 

Jay Cee

New Member
Jul 29, 2019
89
0
0
Forget Base 2, that's just straight up Base 1, or should I say Base i for imaginary. I'd like to see that! Lol
Safe to say, the clocks are still being created seeing as they are pretty much infinite.

Doesn't worry me, it means it's not yet time to go to work :D
 

NHsports123

New Member
Jul 29, 2019
15
0
0
Mine was a bit different.
Code:
i = 1
while i == 1 do
term.clear()
term.setCursorPos(1,1)
print(textutils.formatTime(os.time(), boolean))
sleep(1)
end

The term.clear and term.setSursorPos just clear the screen and resets the cursor so it always puts the time on the top line.

The sleep is just so that there is a delay between time refreshes, no point having it refresh every tick.

The while i == 1 do
"code"
end

Is just an infinite Do loop. I set the variable i to be 1 at the start, so it is always true and so always loops. You could replace the first 2 lines with 'while true do' and it should still work.
I just tried this code and it didn't work.