kingmatt2
|
  |
| Joined: 20 Aug 2011 |
| Total Posts: 6494 |
|
|
| 06 Aug 2013 11:49 AM |
In high detail can someone explain this to me? I know what it does. Just eplain EVERYTHING. Dont put: It clones everything it workpace. What I need to know is WHY are THERE certain THINGs there such as the: for, _, ,, v, ()).
for _,v in pairs(game.Workspace()) do v:clone() end
|
|
|
| Report Abuse |
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 06 Aug 2013 12:09 PM |
Ah, another detail-oriented! You are as I, because I really need a lot of detail to understand things.
First of all, this will not work. This will work:
for _,v in pairs(Workspace:GetChildren()) do v:clone() --.Parent = Workspace end
Now, I shall explain line-by-line. pairs is an iterative function to build on with the for loop. A 'for loop' is a loop that will run through a certain set of data until it reaches a stopping point. When we say for _,v in pairs, we are defining a loop, and telling it run through everything we give it, whilst defining a key and a value. The _ variable will tell us which INDEX we are at, and the v variable tells the VALUE at that index. pairs is no more than a function. The first and only parameter of pairs is the table that it needs to run through.
for _,v in pairs(Workspace:GetChildren()) do The first word identifies a for loop. The next term (_,v) is defining the two variables by which we iterate, where _ is the index and v is the value. Workspace:GetChildren() returns a table of all objects inside of the Workspace. The final constructor, 'do', opens the for loop.
v:clone() This copies all userdata into nothing so far. If we were to set it as a variable, or set its Parent, it would be useful.
end This ends the for loop.
The best way to see what I mean by the key/value relationship is to run this program:
t = {'Alpha', 'Beta', 'Gamma', 'Delta', 'Nu', 'Pi', 'Phi'} for i,v in pairs(t) do print(v..' is the '..tostring(i)..'-index value in the table.') end
table.sort(t) for i,v in pairs(t) do print('After sorting the table, '..v..' is the '..tostring(i)..'-index value in the table.') end |
|
|
| Report Abuse |
|
kingmatt2
|
  |
| Joined: 20 Aug 2011 |
| Total Posts: 6494 |
|
| |