cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 13 Aug 2013 11:42 PM |
function derp(perks)--perks is an object inside a table return tostring(perks.Name),#perks end
hi,amount = derp(game.Workspace:GetChildren())
why would amount return nil? (even though there are stuff in workspace)
shouldnt it return length? |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2013 11:48 PM |
| The "#" operator only returns the number of consecutive non-hashed values. That means counting up from 1, to the first missing number and using the numbers as indexes. So, if you want to get the length, keep track of every time you add an object to the list and increment a value, or use next() or pairs() to add up all of the values. |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 13 Aug 2013 11:52 PM |
im still having a little trouble understanding the next() and pairs() idk how to use them is there a page on roblox wiki in which i can see how to use them? |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2013 11:55 PM |
Pairs: http://wiki.roblox.com/index.php/Pairs#pairs
Next: http://wiki.roblox.com/index.php/Pairs#next |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2013 11:57 PM |
But, just use this code:
local function Length(Table) local Len = 0 for k, v in next, Table do Len = Len + 1 end return Len end |
|
|
| Report Abuse |
|
|
|
| 14 Aug 2013 12:07 AM |
Did ArbiterOfDeath,
Just say what I thought he said?
Gemeric for (I would go research on RealWiki, why it is called Generic-for; who first proposed its inclusion of, inPairs, to the rarified lexicon of prepositions use by Derps to program their robots; and then recursively continue to research, 'til I reached the Invention of the wheel))).
but,
http://wiki.roblox.com/index.php/Generic_for
it is a special, good 'ol For loop used, a lot, in Tables-of-things, which just returns TWO 'Iterators (Is & Js): The Index (Tilte) of the List entry (1,2,3...), and the Contents of the particular entry (or pointer to it, or something. Read the Wiki...)
Used when u don't don't how big the list IS? Or when the list keeps changing, so u can't just stick a for I = 1 to 10 loop; or to be fancy..... Or when u don't want to keep asking, "how big is #list"?
U should prolly always be using it, and get used to it. Taqbles r the way-to-go, and Some Frankenstien invented it.........
--Bri
|
|
|
| Report Abuse |
|
|
|
| 14 Aug 2013 12:11 AM |
*Oh the important part....
It always loops the number of times as the number of things in some List,
Made for Tables....
|
|
|
| Report Abuse |
|
|
| |
|
|
| 14 Aug 2013 12:21 AM |
Lol,
I thought that I was explaining something in a folksy, understandable manner, and got a big "Rejected" for the Arbitor of Death. I will say my prays toniught.
|
|
|
| Report Abuse |
|
|