RMofSBI
(RMofSBI)
September 5, 2022, 4:38pm
#1
I am decent with scripting, but this line is confusing me, can someone please explain it. Clearly it gives the current day, but please explain the string.sub and the parameters so i can understand better. Thanks:
local currentDay = string.sub(os.time(), 1, 3)
paetemc2
(Dragon_bloxy)
September 5, 2022, 4:40pm
#2
it takes the first 3 characters of os.time()
nicemike40
(nicemike40)
September 5, 2022, 4:40pm
#3
This is nonsense, and doesn’t do anything useful that I can tell. os.time()
returns a number of seconds.
RMofSBI
(RMofSBI)
September 5, 2022, 4:43pm
#4
To clarify more, the next few lines of code are this:
local currentDay = string.sub(os.time(), 1, 3)
if currentDay == "Thu" then --thursday
badgeService:AwardBadge(player.UserId, badgeId)
end
And yes it wasn’t making sense to me either, so I thought i would ask the forum.
nicemike40
(nicemike40)
September 5, 2022, 4:48pm
#5
os.time()
returns a number like 1662396278
string.sub(os.time(), 1, 3)
returns string with the first three numbers like "166"
I don’t see how that would ever equal "Thu"
.
Here’s a way to actually do that:
local currentDay = DateTime.now():FormatLocalTime("ddd", "en-us")
You can also use :FormatUniversalTime()
instead if you want it to be based on GMT instead of the user/server’s local timezone.
1 Like
RMofSBI
(RMofSBI)
September 5, 2022, 4:50pm
#6
Yes i just ran a print and saw that so i was confused… thanks for clarifying, I thought i was going nuts!
Forummer
(Forummer)
September 6, 2022, 2:53pm
#7
Technically would be based on UTC.
1 Like