|
| 30 Oct 2016 07:55 AM |
I'm trying to work on a script that turns off all the lights at my unfinished apartment when it's 8AM and turns on them when it's 6PM. I worked hard making all the variables for all the lights,then proceed with the "while" loop,then use the "if,then" statements to work my script. However,no matter how many times I modify and try to correct everything,it still doesn't work.Is something wrong with my script,how to make it work?I hope I get an answer that solves my problem in 1-2 hours so that I can complete my objective today (script the apartment lightings). __________________________________________________________________________________________lobbylight1 = game.Workspace.LobbyLight1.Bulb lobbylight2 = game.Workspace.LobbyLight2.Bulb corridorlight1=game.Workspace.CorridorLight1.Bulb corridorlight2=game.Workspace.CorridorLight2.Bulb corridorlight3=game.Workspace.CorridorLight3.Bulb corridorlight4=game.Workspace.CorridorLight4.Bulb corridorlight5=game.Workspace.CorridorLight5.Bulb corridorlight6=game.Workspace.CorridorLight6.Bulb while true do if game.Lighting:GetMinutesAfterMidnight() == 8 * 60 then lobbylight1.SurfaceLight.Enabled = false lobbylight2.SurfaceLight.Enabled = false corridorlight1.PointLight.Enabled = false corridorlight2.PointLight.Enabled = false corridorlight3.PointLight.Enabled = false corridorlight4.PointLight.Enabled = false corridorlight5.PointLight.Enabled = false corridorlight6.PointLight.Enabled = false end if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then lobbylight1.SurfaceLight.Enabled = true lobbylight2.SurfaceLight.Enabled = true corridorlight1.PointLight.Enabled = true corridorlight2.PointLight.Enabled = true corridorlight3.PointLight.Enabled = true corridorlight4.PointLight.Enabled = true corridorlight5.PointLight.Enabled = true corridorlight6.PointLight.Enabled = true end wait(1) end |
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 08:00 AM |
| Is the time ever equal to exactly that time |
|
|
| Report Abuse |
|
|
Aliics
|
  |
| Joined: 29 Sep 2014 |
| Total Posts: 471 |
|
|
| 30 Oct 2016 08:02 AM |
lights = { lobbylight1 = game.Workspace.LobbyLight1.Bulb, lobbylight2 = game.Workspace.LobbyLight2.Bulb, corridorlight1=game.Workspace.CorridorLight1.Bulb, corridorlight2=game.Workspace.CorridorLight2.Bulb, corridorlight3=game.Workspace.CorridorLight3.Bulb, corridorlight4=game.Workspace.CorridorLight4.Bulb, corridorlight5=game.Workspace.CorridorLight5.Bulb, corridorlight6=game.Workspace.CorridorLight6.Bulb, }
function lights_enabled(bool) for i, v in pairs (lights) do v.SurfaceLight.Enabled = bool end end
while wait() do local time_check = game.Lighting:GetMinutesAfterMidnight() if time_check > 8 * 60 and time_check < 18 * 60 then lights_enabled(false) else lights_enabled(true) end end
|
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 08:10 AM |
| Not to say I'm not guilty of doing it, but Aliic that won't help them learn to script, they need to figure out how to solve these problems themself not have someone #### #### they probably can't understand And if you are going ## ### and out code them at least use the .Changed event instead of a while loop |
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 08:45 AM |
@128Gigabytes It did help me to learn and improve my scripting knowledge,it reminds me to do these: 1.Firstly,we need to teach the computer about our bulbs using the programming langauge (LUA).create variables of all the lights in my apartment.Then,make a table (a list) of all the bulbs in my apartment.
2.Secondly,create a function (lines of script that does the code).
3.Use the for loop concept (for i,v) v=variable,therefore variable refers to the Pointlight property of the bulbs.
4.It assisted me to understand functions with parameters as well. -functions lights-enabled (bool),bool refers to true or false,therefore we later call the function(true ELSE false) which means if the time is between 8AM and 6PM,then the "lights_enabled(true)" will make the boolean property of Pointlight of the bulbs enabled,which turns on the lights. Add an else,which means OR ELSE, (if not between 8AM-6PM),then "lights_enabled(false)" makes all the lights turn off.
5.I think that's all,really helpful. |
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 08:47 AM |
@Aliics I appreciate your help,I'll refer this when making other scripts related to this concept. You actually forgot to make variables for all the lights,or you just wanted to guide me and let me do the finishing. So,it didn't work at first and I did some tweaking,as shown below: ________________________________________________________________________________________ lobbylight1 = game.Workspace.LobbyLight1.Bulb lobbylight2 =game.Workspace.LobbyLight2.Bulb corridorlight1=game.Workspace.CorridorLight1.Bulb corridorlight2=game.Workspace.CorridorLight2.Bulb corridorlight3=game.Workspace.CorridorLight3.Bulb corridorlight4=game.Workspace.CorridorLight4.Bulb corridorlight5=game.Workspace.CorridorLight5.Bulb corridorlight6=game.Workspace.CorridorLight6.Bulb lights = {l####################################################################################################corridorlight6}
function lights_enabled(bool) for i, v in pairs (lights) do v.PointLight.Enabled = bool end end
while wait() do local time_check = game.Lighting:GetMinutesAfterMidnight() if time_check > 8 * 60 and time_check < 18 * 60 then lights_enabled(false) else lights_enabled(true) end end |
|
|
| Report Abuse |
|
|