generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Can someone explain the "for" and k, v, i (Pairs)

Previous Thread :: Next Thread 
TheOpticsGuy is not online. TheOpticsGuy
Joined: 25 Jan 2011
Total Posts: 223
31 May 2014 06:48 PM
Shoot and thanks :)
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
31 May 2014 06:53 PM
local tablename = {1, "Panda", "Potato"}

for key, value in pairs(tablename) do
print(key, value)
end

>1 1
>2 Panda
>3 Potato


Basically key is the index of the tablename, and value is tablename[key]

Report Abuse
TheOpticsGuy is not online. TheOpticsGuy
Joined: 25 Jan 2011
Total Posts: 223
31 May 2014 06:57 PM
in pairs?
Report Abuse
zakarq is not online. zakarq
Joined: 10 Oct 2010
Total Posts: 883
31 May 2014 06:58 PM
In pairs = in order
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
31 May 2014 06:59 PM
^ no.
Report Abuse
zakarq is not online. zakarq
Joined: 10 Oct 2010
Total Posts: 883
31 May 2014 06:59 PM
oh
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
31 May 2014 07:01 PM
ipairs is in order
Report Abuse
TheOpticsGuy is not online. TheOpticsGuy
Joined: 25 Jan 2011
Total Posts: 223
31 May 2014 07:06 PM
whats in pairs then?
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
31 May 2014 07:07 PM
for index, value in ipairs(table) do
print(index..":"..value)
end

for index, value in pairs(table) do
print(index..":"..value)
end

for index=1,#table do
print(index..":"..table[index])
end
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
31 May 2014 07:07 PM
Same as ipairs except its not in order.

But if you have a table set up like this

local table = {}
table["Panda"] = 1

pairs can detect the "Panda" key
ipairs cannot
Report Abuse
TheOpticsGuy is not online. TheOpticsGuy
Joined: 25 Jan 2011
Total Posts: 223
31 May 2014 07:13 PM
Sorry for being so stupid but i am learning what is this {}

So if i understand correctly your setting a local variable named table and its value is {}

Then after that i have no idea what you did.
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
31 May 2014 07:15 PM
its a table

its basicly something that can store multiple things

GetChildren() returns a table

MyTable = {"Hi","By","this is the third object!","meh, im #4!"}


print(MyTable[1])

>Hi

print(MyTable[3])

>this is the third object!

print(MyTable[2])

>By

print(MyTable[4])

>meh, im #4!


http://wiki.roblox.com/index.php/Table
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
31 May 2014 07:16 PM
so you could say

T = {p = "Hi"}

print(T.p)

>Hi

or even

T = {}
T.p = "Hi"

print(T.p(

>Hi

or

T = {}
T["p"] = "Hi"
print(T["p"])
Report Abuse
TheOpticsGuy is not online. TheOpticsGuy
Joined: 25 Jan 2011
Total Posts: 223
31 May 2014 07:20 PM
Very good reply thank you.
Report Abuse
TheOpticsGuy is not online. TheOpticsGuy
Joined: 25 Jan 2011
Total Posts: 223
01 Jun 2014 10:29 AM
Sorry to b so nooby what is the key and the value :)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Jun 2014 01:37 PM
myTable = {"a", "b", "c"};

key -> value
1 -> "a"
2 -> "b"
3 -> "c"
values are indexable by: myTable[key]
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image