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

How could I make this day/night cycle script more efficient?

Asked by
TMGOR 20
7 years ago

As you've noticed (by how many questions I've asked) I'm a beginner on my 4th(?) day of learning how to script. For my current project, I have scripted this using some help with functions from the wikia. Although I'm very proud of what a useful script I've made, it however bugs me about the length and structure of the code. Could I get some ideas about the script and how to make it better and more efficient? For example - Should I use if hour % 24 == 0 instead of if hour > 23? Thanks in advance!

hour = 0
day = 0 
minutes = 0

while true do
    wait(1)
    minutes = minutes + 1
    if minutes > 60 then
        minutes = 0
        hour = hour + 1
    end
    game.Lighting:SetMinutesAfterMidnight(hour*60)
    if hour > 23 then
        hour = 0
        day = day + 1
    end 
    print("It is day " .. tostring(day) .. tostring(" and ") .. tostring(minutes) .. tostring(" minutes past ") .. tostring(hour))
end


1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Try this:

Minutes

while wait(60) do
    game.Lighting:SetMinutesAfterMidnight(game.Lighting:GetMinutesAfterMidnight() + 1)
end

Seconds

while wait(1) do
    game.Lighting:SetMinutesAfterMidnight(game.Lighting:GetMinutesAfterMidnight() + 0.0167)
end
0
Hi! I want to keep the seconds variable and, forgive me if I'm wrong, that replaces it? TMGOR 20 — 7y
0
To get the time, use game.Lighting.TimeOfDay AlphaGamer150 101 — 7y
Ad

Answer this question