koen500
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 2277 |
|
|
| 04 Jul 2012 05:19 AM |
Idk how to use tables with for... Can someone explain to me. I started making an admin script but I really need to know how this works. |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2012 05:26 AM |
table1 = ("Name", "Name2")
for i, v in pairs(table1) do -- Iterates through table1 |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 04 Jul 2012 05:26 AM |
Pretty easy:
people = {"blah","Narb","Penguin","bear"}
for number, object in pairs(people) do print(object.." is #"..number) end
--Or
for num=1,#people do print(people[num].." is #"..num) end |
|
|
| Report Abuse |
|
|
koen500
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 2277 |
|
|
| 04 Jul 2012 05:28 AM |
@gg: Why i, v in pairs. I mostly see k, v in pairs? @zarz: I don't understand... |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2012 05:32 AM |
@koen
i stands as a variable for the loop, just like a numeric for loop does.
I.E: for i = 1, 10 do
So in a generic for loop (which is what you would use for a table), i is the same thing, just used differently.
An example of how a generic for loop is used in a table would be this:
allowed = ("koen500", "Friend") -- Player names that will be 'allowed'.
game.Players.PlayerAdded:connect(function(plr) for i, v in pairs(allowed) do if plr.Name ~= v then plr:Destroy() end end) |
|
|
| Report Abuse |
|
|
Cheater
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 5258 |
|
|
| 04 Jul 2012 05:32 AM |
No diference between k and i.
Just look up the for functions in the wiki. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 04 Jul 2012 05:37 AM |
k,i are just variables. It can be anything laik
for apples, pears in pairs(blah) do |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2012 06:02 AM |
@zars
> pears > pairs
teeehee |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 04 Jul 2012 06:10 AM |
for tiers, pears in pairs(liers) do print("Wut?") end |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2012 06:11 AM |
incorrect
you didn't declare an array/table named liers
liar |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 04 Jul 2012 06:14 AM |
| Umt i dun wanna give u mah code, cuz u will steal it and claim mah script as urs :( Dun't hurt mah feelings blah QQ~Average person who asks for help, but doesn't give whole code. |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2012 06:16 AM |
| I haven't ever seen someone post something of that sort on SH before.. That would be quite odd. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 04 Jul 2012 06:18 AM |
| Then you got to be new.... I've seen alot of posts here, asking for help even if they didin't give whole code. |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2012 06:20 AM |
No, I mean that I haven't seen anyone not post code because they don't want it stolen.
I've seen plenty of people who don't post code and expect us to just magically know the issue. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 04 Jul 2012 06:31 AM |
| Well, of course they don't want to admit that, that they're cowards, but if you think, then yeah that's why... How ironicaly.. People steals others scripts, and are afraid to post theyr own code, because some one might claim copyright of it. |
|
|
| Report Abuse |
|
|
koen500
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 2277 |
|
| |
|