|
| 21 May 2012 07:07 PM |
Note: After making less informative tutorials, this one will be a try-harder tutorial **What Are Day/Night Scripts?** Well, to explain it, Day/Night Scripts may look complicated, but they create a simple process in which the Sun sets, moon rises, moon sets, sun rises and so on. They are useful in roleplays, story-based games and other things. **How To Make A Day/Night Script** Well, open Roblox Studio, and start a new place. Now, do Insert > Object > Script, and open the Script Editor. Now, we are going to make this script a little customizable, so start out by adding this:
speed = 6
Ok, now, this will be used to change how fast the sun and moon go, changing the length of the day. Now let's add this to our script:
sec = 0 min = 0 hour = 0 while true do game.Lighting.TimeOfDay = ""..hour..":"..min..":"..sec.."" sec = sec + (5*speed) if sec >= 60 then sec = 0 min = min + 1 end if min >= 60 then min = 0 hour = hour + 1 end if hour >= 24 then hour = 0 end wait(0.03) end
Now, this might look like a bunch of mumbo-jumbo to some of you, but all of this together creates a smooth feature where the sun and moon move, and the sky changes from Day to Night. Now, this script changes the TimeOfDay inside the Lighting, which you can find in Workspace. Traditionally, you can change the TimeOfDay to a non-moving time, but this is useful too. Now, at the top where you put speed = 6, change the 6 to the speed you want the Day to last. 1 is slowest and 6 is fastest. So altogether you need to have this:
speed = 6
sec = 0 min = 0 hour = 0 while true do game.Lighting.TimeOfDay = ""..hour..":"..min..":"..sec.."" sec = sec + (5*speed) if sec >= 60 then sec = 0 min = min + 1 end if min >= 60 then min = 0 hour = hour + 1 end if hour >= 24 then hour = 0 end wait(0.03) end
There are many other ways to do this, but I found this to be the simplest way, for now.
Happy Scripting!
-GD987
|
|
|
| Report Abuse |
|
|
MajorTyco
|
  |
| Joined: 09 Apr 2010 |
| Total Posts: 1989 |
|
|
| 21 May 2012 07:11 PM |
I find that jumping to specific times, AT specific times is much easier, simpler, and less time-consuming than having an actual clock and progressing as an actual scaled day, leaving me more time to write things other than day/night scripts.
Not many people really notice the abrupt changes in the time of day- At least not in any of the places I've made/visited
"I remain just one thing, and one thing only — and that is a clown. It places me on a far higher plane than any politician."-- Charlie Chaplin |
|
|
| Report Abuse |
|
|
|
| 21 May 2012 07:12 PM |
I prefer a smooth transition actually, but we all have our opinions :D
~Let the Flame Wars begin! And may the odds NEVER be in your favor!~ |
|
|
| Report Abuse |
|
|
|
| 21 May 2012 07:13 PM |
This looks like my script ALOT like my script but with un-needed stuff
if sec >= 60 then sec = 0 min = min + 1 end if min >= 60 then min = 0 hour = hour + 1 end if hour >= 24 then hour = 0 end wait(0.03) end
This isnt needed because after sec reaches 60 it will automatically change to 0 and the minutes will be added one more, also with the hour. And... Were you got that from? Cause it looks like this:
sec = 0 -- The TimeOfDay will start with 0 seconds, min = 0 -- 0 minutes and hrs = 0 -- 0 hours. while true do game.Lighting.TimeOfDay = (hrs ..":" ..min ..":" ..sec) --Do not change min = min+1 --one millisecond is one minute, change to hrs, min or sec. wait() --Time it waits to perform the same event end --Script by vampirexevipex
Which you can find here: http://www.roblox.com/Simple-editable-time-script-item?id=81141635 |
|
|
| Report Abuse |
|
|
|
| 21 May 2012 07:15 PM |
Actually, I made this myself... but it's just how I learned and now the only way I do it :D
~Let the Flame Wars begin! And may the odds NEVER be in your favor!~ |
|
|
| Report Abuse |
|
|
|
| 21 May 2012 07:20 PM |
@Green Ok, congrats ,and i see u are learning how to script, you're doing pretty well. Good luck in that. :P |
|
|
| Report Abuse |
|
|
|
| 21 May 2012 07:22 PM |
Lol thanks 8P
~Let the Flame Wars begin! And may the odds NEVER be in your favor!~ |
|
|
| Report Abuse |
|
|
Aerideyn
|
  |
| Joined: 16 Jan 2010 |
| Total Posts: 1882 |
|
|
| 21 May 2012 07:36 PM |
Those who are still at a beginner level at scripting should be the one reading tutorials - not making them.
speed = 3 while true do minutes = game.Lighting:GetMinutesAfterMidnight() for j= 0,60/speed do game.Lighting:SetMinutesAfterMidnight(minutes + (j/(60/speed))) wait() end end
thats all you need for this script.. |
|
|
| Report Abuse |
|
|
MajorTyco
|
  |
| Joined: 09 Apr 2010 |
| Total Posts: 1989 |
|
|
| 21 May 2012 07:43 PM |
"Those who can't do- Teach"
"I remain just one thing, and one thing only — and that is a clown. It places me on a far higher plane than any politician."-- Charlie Chaplin |
|
|
| Report Abuse |
|
|
Aerideyn
|
  |
| Joined: 16 Jan 2010 |
| Total Posts: 1882 |
|
|
| 21 May 2012 07:52 PM |
But in the intrest of feedback..
Errors:
"...TimeOfDay inside the Lighting, which you can find in Workspace..." Lighting is not found in workspace, it is found under "game"
Bad practice: 1) use of wait(0.03); wait() will cause a thread to yeild until the next frame, if the time is less than what was requested to wait for, it will yeild again and so on. So you do not specify an argument wait() will wait the duration of 1 frame. If you specify a time less than 1 frame it will wait 1 frame anyway. Since you are using a script to create an animated effect it is important to have it update every frame. Hence use wait(); 2) ""..hour..":"..min..":"..sec.."" the use of "" does not accomplish anything, i suspect you are using it to make a space before you print hour? try this. print("" .. "hi".."".."test") >hitest if you want a space you need to add a space. print("" .. "hi".." ".."test") hi test
Improvement needed: 1)you do not explain string concatenation, but yet you use it. 2)You use string concatenation when a easier to use method is available (this is for newbs isnt it?) Get/SetMinutesAfterMidnight() 3)you post the script twice without any change in it?
|
|
|
| Report Abuse |
|
|
|
| 21 May 2012 08:12 PM |
Stop. Just stop.
Yes, I realize I accidently put Lighting under "Workspace", but that was a typo. But, this is the way I make MY scripts, that is the way you make it. I was trying to explain this for beginners. You do not need to call me one just because you wanted me to do it your way. This script works, that the only thing that matters.
~Let the Flame Wars begin! And may the odds NEVER be in your favor!~ |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 21 May 2012 09:24 PM |
| What the heck kind of tutorial is this???? |
|
|
| Report Abuse |
|
|