Hello. I've been working on a timer recently and I want to make it very easy to read, so what i've done is made code that converts day, hour, minute variables etc into an easy to read time format for example variables are day: 2 hour: 1 minute: 0 second: 16 it would return "2 Days, 1 Hour, 16 Seconds"
or day: 1 hour: 0 minute: 5 second: 4 would return "1 Day, 5 Minutes, 4 Seconds"
Here is the code: https://pastebin.com/raw/M4WwSZHE
as you can tell the code is WAY TOO LONG. WAY too long. I have done a lot of searching and I cant find anything to help make this MESS any shorter I would really appreciate it if you could tell me a way to make this shorter
Thanks!
The format
function, formats a string. In string patterns, %d
is a digit character.
In this case, you can do something like this
```lua local function format(hr, min, sec) return string.format("%d Hours, %d Minutes, %d Seconds", hr, min, sec); end
print(format(12, 24, 36)); --> 12 Hours, 24 Minutes, 36 Seconds ```
You can add checks so if the number is 1
you can make it say 1 Hour
(for example) rather than 1 Hours
.