form2275
|
  |
| Joined: 09 Jul 2007 |
| Total Posts: 6041 |
|
|
| 24 Jul 2011 10:57 PM |
I had an example, but I accidently deleted it. :/
I thing it was something like:
table={} for _,v in pairs table do end |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2011 10:59 PM |
| uhh gosh i suck at lua i need help. |
|
|
| Report Abuse |
|
|
form2275
|
  |
| Joined: 09 Jul 2007 |
| Total Posts: 6041 |
|
|
| 24 Jul 2011 11:01 PM |
I found my mistake. I forgot the (). sorry.
it should be:
table={} for _,v in pairs(table) do end |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2011 11:03 PM |
table = { "ABC , 123 }
for i,v in pairs(table) do
print(i .. " " .. v)
end
>1 ABC >2 123
i (the first argument) is the index of the value in the table, and v (the second value) is the value of that index in the table. |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2011 11:04 PM |
| Fixes, forgot to close the quote "ABC" and should've said v is the second argument, not value. |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2011 11:04 PM |
I suggest you use next, instead, since it is more efficient.
local tab = {"A", "B", "C"}
for i, letter in next, tab do print(letter) end
It runs faster than pairs. |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2011 11:06 PM |
| What is 'next?' i've never heard of that... an explanation or wiki page would be fantastic, I'm always interested in new concepts :D |
|
|
| Report Abuse |
|
|
form2275
|
  |
| Joined: 09 Jul 2007 |
| Total Posts: 6041 |
|
|
| 24 Jul 2011 11:39 PM |
@JulienDethurens Thanks, never heard of next before.
@BladzofChaos70 Thanks for in info on in pairs() |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2011 11:44 PM |
"What is 'next?' i've never heard of that... an explanation or wiki page would be fantastic, I'm always interested in new concepts :D"
Pairs and ipairs both use next. If you need info about it, go look on the Lua reference manual on lua.org. |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2011 12:01 AM |
I apologize for having never heard of that term before, next time I will try to know the thing I don't know about. Now that i've heard about it it makes sense & i figured pairs/ipairs did something of the sort.
(btw, I apologize for my for statement if you weren't intending to be rude, that's just how I first interpreted it) |
|
|
| Report Abuse |
|
|
Spectrumw
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
|
| 25 Jul 2011 12:03 AM |
"I will try to know the thing I don't know about."
Oh mai D: paradox much? |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2011 12:05 AM |
| Just so you know, using a numeric for loop is way more efficient than using pairs/ipairs/next [PROVEN]. |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2011 12:06 AM |
| That was the point, the way I first interpreted what he said it seemed like he was annoyed that I didn't know about 'next' and was annoyed that I was asking about it, so basically for his convenience next time I'll just somehow know about something instead of asking. (Aren't retorts/jokes always the best when they have to be explained? XD) |
|
|
| Report Abuse |
|
|
form2275
|
  |
| Joined: 09 Jul 2007 |
| Total Posts: 6041 |
|
|
| 25 Jul 2011 12:23 AM |
I was going to use this for a part of my script to get all the players.
Thanks.
for _,player in next, game.Players:GetChildren() do end
--@JulienDethurens, Is the bellow script what you meant by numeric for loop?
player=game.Players:GetChildren() for i,1#player do end |
|
|
| Report Abuse |
|
|