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: Easy question

Previous Thread :: Next Thread 
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
13 May 2014 02:57 PM
Can someone exsplain for in scripting for me please? The wiki dosen't help.
If you have a good clear exsplanation of for please comment it.


I see stuff like
for i,v in pairs
or
for _,r
what is that stuff??
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
13 May 2014 03:23 PM
in pairs is a loop that goes through a table. A table is basically one variable with multiple values.

local tab = {1, 6, 15, 2}

You can access each value of a table like this:

print(tab[1]) >>1
print(tab[2]) >>6
print(tab[4]) >>2


If you want to do something with every value of a table, you can use an in pairs loop.

for index, value in pairs(tab) do --name index and value whatever you want.
print(index .. ", " .. value)
end

This loop's index will increase by one each time, and the value is equal to tab[index]. If you were to run that script, this is what would get printed out.

1, 1
2, 6
3, 15
4, 2
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
13 May 2014 03:28 PM
'This loop's index will increase by one each time'
Not always, it will just get the next key. For example

local tab = {};
tab[5] = "hello";

for index, value in pairs(tab) do
print(index, value);
end

5 hello
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
13 May 2014 03:29 PM
^ Oh, good point.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
13 May 2014 03:30 PM
OP, be sure, if you have non-numerical keys, you use pairs (or next) and not numeric for or ipairs. As those iterate over numerical-keys.
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
13 May 2014 05:10 PM
Thanks guys, cleared it up a bit.
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