I assume the t is suppose to be an i ? [after the first math.floor]
Correct, I was assuming t for time, it is edited now.
It works but when it goes under 10 seconds, it looks like: 0:4 instead of 0:04. Any ideas how to fix?
Never mind I found a solution. For anyone who sees this post in the future. Here is my script:
for i = 15, 0,-1 do
local minute = tostring(math.floor(i/60))
local sec = math.floor(i%60)
if sec < 10 then
sec = "0".. tostring(math.floor(i%60))
end
status("Intermission: " .. minute .. ":" .. sec)
wait(1)
end
I was going to say to concat another zero if it’s under 10, but looks like you solved that problem.
Just saying; there’s a better way to handle your seconds. I want to introduce you to a cool string pattern that I learned the other day, %.2i
. This pattern will insert a 0 as the first number if the number is below 9. Other ways to write this are %.2d
, %02d
and %02i
. You can also replace 2 with 3 so it’s under 99 for a 0 to be added, so on.
Here’s some code that will automatically insert that awesome 0 for you. Before I post that, I’d like to point out that your concatenation could’ve used the calculated sec
value instead of doing it again.
for i = 15, 0, -1 do
local minutes = math.floor(i/60)
local seconds = math.floor(i%60)
status(string.format("Intermission: %i:%.2i", minutes, seconds))
wait(1)
end
cc @ThousandDegreeKnife
I will give this a try! Thank you!
Hey! What’s the status? When I try to use it creates a error between that.
that was 2 years ago lol
dont bumb things that dont need to be
The response I created here was based off of what OP originally resolved their question with which involved a status function of some kind. My code was only intended to improve on theirs. Presumably status is a function that’s meant to update a value of some kind somewhere.
You can write your own status code. The main idea, if you’re looking to my post for formatting numbers, should be everything except the status function so that means the string formatting and calculations done to retrieve the time. It is a pretty simple piece of code but a little old and missing some parts like some subtractions but it still gets the job done.
@AC_Starmarine It’s only a bump if the post doesn’t contribute to the thread. Asking a question is fine, leave it be. Flag a post if you believe it doesn’t belong rather than calling someone out for it.
Alright! Thank you. I was just scrolling through things to see if I can get an Idea of a code that will fix my problem as well with the format of the Numbers (0:0).
thx for the reply, you heled me a lot
i mean helped me a lot. Thx again
it worked thanks man greatly appreciated evem if i didnt create the post
damn this is old but status is underlined? the status("intermission:
Whats the status? It underline sit in red, and im very confused.
Status is a function that the person made to set the text of a certain label to the passed value
How do I make it so it loops whenever I want it to again?
Thanks so much very useful to know.