Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making something print at a specified time?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a sound play when a raid starts which begins at a specific time, (irl time) but when I tried to print something it didn't work.

local hour = os.date("!*t") ["hour"]
local minute = os.date("!*t") ["min"]

if hour == 7 and minute == 5 then
    print("Hmm")
end

(I used print just to test it)

[EDIT]

local hour = os.date("!*t") ["hour"]
local minute = os.date("!*t") ["min"]

while true do
    wait() --i added this so my game doesnt break
if hour == 2 and minute == 55 then
    print("Hmm")
end
end
0
its important to know os.date uses UTC so maybe it didnt pass that proIua 32 — 5y
0
converts your hour to UTC hour proIua 32 — 5y
0
That code will only check once as soon as the game runs, so if it's not the correct time as soon as you hit the start button it wont work. You could put it in a loop instead to repeatedly check. mattscy 3725 — 5y
0
@prolua I know it goes to UTC I just changed it CaptainAlien132 225 — 5y
View all comments (5 more)
0
@mattscy I added a loop but it still didn't print CaptainAlien132 225 — 5y
0
while true do iWagen 5 — 5y
0
What other loop would I use?? CaptainAlien132 225 — 5y
0
It works fine for me. Show us the updated version with your while loop. Cousin_Potato 129 — 5y
0
@Cousin_Potato added it CaptainAlien132 225 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You need to also update the time variables inside the loop, otherwise they will be set only once at the beginning of the script and never again even as the clock increments.

while true do
    local hour = os.date("!*t") ["hour"]
    local minute = os.date("!*t") ["min"]

    if hour == 14 and minute == 17 then
        print("Hmm")
    end 
    wait()
end

Ad

Answer this question