@EgizianoEG @puf0chek
This is actually a Very inefficient way to check time. there are a lot of better ways to check the time rather than using elseifs
, I’ll give an Example:
It would be a lot Easier to use string.format
to concatenate instead of using ..
as that can make your script look weird.
To Put Simply:
%
is something to replace
%s
means a string
%d
means a number
(Preferablly an Integer)
However, the Item you want is %02i
which will add a 0
Digit to your number, so if you had the Number 1
and format it to %02i
, it will give you 01
, if your number is ten, this will return 10
, you will have to add another Digit to the format so: %03i
and so on, this will give you 010
, this is useful so you don’t have to use a bunch of if statements to add a 0
to your String:
This should be the Format if I’m Correct:
string.format("Day %d|%02i:%02i|%s", Days, Hours, Real, DayType)
Printing it will give you these Results:
Summary
print(string.format("Day %d|%02i:%02i|%s", 2, 1, 5, "Hello")) -- "Day 2|01:05|Hello"
print(string.format("Day %d|%02i:%02i|%s", 2, 12, 50, "Noon")) --"Day 2|12:50|Noon"
Plus, Its Generally better to swap out the if
statements and use a table:
local Times = {
["Morning"] = 0; -- 12 AM
["Dawn"] = 6; -- 6 AM
["Noon"] = 12; -- 12 PM
["Evening"] = 13; -- 1 PM
["Afternoon"] = 15; -- 3 PM
["Night"] = 20; -- 8 PM
}
So, In this case, we can do:
local DayTime
local ff = -1 -- found Format (Used to assist the for loop in finding the format)
for dt, x in Times do
if Hours >= x and Hours > ff then -- checks the number and gets DayType
DayTime = dt -- new DayType
end
end
So now you have a good system to use! What now, then you should format your code from the example above.