|
| 15 Jul 2015 07:34 PM |
| Is this what I would use if I wanted to find all of the lights in my game and turn them on? If not what would I use? |
|
|
| Report Abuse |
|
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 15 Jul 2015 08:48 PM |
for i,v in next, workspace:GetChildren() do if v:IsA("PointLight") then v.Enabled = true end end
"Talk is cheap. Show me the code." - Linus Torvalds |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 15 Jul 2015 08:49 PM |
| Well, if all the lights are in the same model or something, yeah that'd be fine. Otherwise you'd need a recursive function to search through the entire game. |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2015 08:50 PM |
for i = 1,#200 do -- change 200 to the num of lights ypcall(function()game:FindFirstChild("LightName",true).Enabled=true;end) end |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2015 10:00 PM |
| Can someone explain it? I would like to understand what the I and V mean etc |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2015 10:02 PM |
| I will gladly explain to someone who actually shows interest in learning. I wish we had more people like you around here! Let me write up some code with comments. I'll be back in a few minutes. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 15 Jul 2015 10:06 PM |
i (index) will find the number of objects. v (variable) will set the variable to those objects.
if you have a model with 4 bricks then the i (index) would = 4. The v (variable) can be used to manipulate the ojects
for i,v in next, model:GetChildren() do print(i) print(v.Name) end
Output: 1 Part 2 Part 3 Part 4 Part
"Talk is cheap. Show me the code." - Linus Torvalds |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2015 10:08 PM |
local count = 0 -- Count is the variable counting how many players there are
for _,Player in next, game.Players:GetChildren() do -- This runs a loop as many times as there are children in players count = count + 1 -- Every time this loop is run, count becomes + 1 higher wait() -- always a good idea to put waits in loops end
print(count) -- Prints only after the loop above has run, thus printing the number of players
This is one example of a generic for loop. You brought up a for loop that uses for i,v in pairs do, which is the same exact thing. In the example I provided you, I use for _,Players in next, do but I could have used for i,v in next, and received the exact same information. They are simply variables. To make myself clear, look at the following two examples. They are exactly the same, the only difference being how I word my variables.
for i,v in pairs(game.Workspace) do v:Destroy() wait() end
for _,Obj in pairs(game.Workspace) do Obj:Destroy() wait() end
Those two generic for loops do the same thing, the difference? The way I word my variables. You can name your variables anything, but its suggested that you use the status quo variables.
For more reference, check out Roblox's wiki on generic fors: http://wiki.roblox.com/index.php?title=Generic_for
If you have any questions, don't feel any hesitation in asking. The best way to learn is to ask questions. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2015 11:16 AM |
Thanks guys! I think I'm starting to get it.
@Cubes4Life would you mind if I PM'd you if I had a question? |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2015 11:19 AM |
| http://wiki.roblox.com/index.php?title=Generic_for |
|
|
| Report Abuse |
|
|
redlo43
|
  |
| Joined: 16 Feb 2011 |
| Total Posts: 4722 |
|
|
| 16 Jul 2015 11:25 AM |
| regular fors are more efficient in your case |
|
|
| Report Abuse |
|
|