|
| 31 Jul 2014 06:05 AM |
I dont see anything about on the wiki. What does: " for _, " do? |
|
|
| Report Abuse |
|
|
| 31 Jul 2014 06:17 AM |
LIES
how dare you disgrace the roblox wiki! look up "for loops" |
|
|
| Report Abuse |
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
|
| 31 Jul 2014 06:51 AM |
"for _," doesn't do anything. What you're referring to is the generic for loop:
for i, v in pairs(t) do end
And "_" is a valid parameter (variable) name, there for you can do something like:
for _, v in pairs(t) do end
Or:
for i, _ in pairs(t) do end
OR EVEN:
for _, _, _, _, _, _ in pairs(t) do end -- magic
OR EVEN:
for _,_,_,_,_,_ in _,_,_,_,_,_ do end
That is valid Lua code. It will compile. However, it will error once ran. To prevent that, you can add this right above it:
function _() end
Also, I should note that this is not the only use of the generic for loop, pairs returns an iterator, and you can use your own iterators. For example:
function iterator() return "potato", "cow", "cake" end
for a, b, c in iterator do print(a, b, c) end
That will repeatedly print potato cow cake. And you can pass along your own arguments to the iterator, which lets you do some interesting things:
function iterator(wisdom, morewisdom) return morewisdom .. wisdom end
for wisdom in iterator, "potato", "starterwisdom" do print(wisdom) end
Of course, this isn't really how you would want to build your iterators, but I'm just showing you the possibilities. =O |
|
|
| Report Abuse |
|