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 I get an explaination on a few things please?

Previous Thread :: Next Thread 
L1kkleC is not online. L1kkleC
Joined: 11 Nov 2011
Total Posts: 961
16 Nov 2014 03:54 PM
What is i?

I see it all the time when its to do with numbers.

Like I'll see

For i = 0, 0.5, 1

Confused on that!



Also, what is this?

_, what's with that? Elaborate please.
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
16 Nov 2014 03:58 PM
for i = 1, 5, 2 do
-- Stuff
end

So, it's a loop so it repeats to code where Stuff is at.

'i' is actually a variable.

The 1 represents what 'i' will equal when the loop starts.

5 is the maximum number 'i' can be. The number can be 5, but it cannot be over 5.

The 2 is how much 'i' will be added by after each loop.



In this instance, i will equal:

1
3
5

And stops from there since 7 is > 5.
Report Abuse
L1kkleC is not online. L1kkleC
Joined: 11 Nov 2011
Total Posts: 961
16 Nov 2014 04:01 PM
So I had like its own background to it.
So you could say i has its own thing like while true do, true, false, end, for, if etc.
Report Abuse
Xsitsu is not online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
16 Nov 2014 04:02 PM
"i" is just the name of a variable that is used in an iterator function. It can be named anything, but it is commonly given the name of "i" because it is only 1 character, and it is easy to remember (i is for iteration)

Whenever you use a for loop such as:

for i = 1, 10 do
print(i)
end

you use a variable to count your place in the loop. This variable can be given any name you want, just like all other variables can.

There's also another type of for loop.

for _, v in pairs(A_Table) do
--stuff
end

This is the pairs type of for loop. Instead of one variable, it uses two. The first variable "_" is the index, and the second v ariable "v" is the value. These variables can be given any name you want, but these are two very common names for them.

The for pairs loop iterates over a table, instead of just counting like the regular for loop does. the for pairs loop will go over every entry in a table and do whatever you told it to do.

"_" is usually given as the index variable name when you don't care about the index. An example would be where you just want to change the name of all the parts in a table.

for _, v in pairs(myTable) do
v.Name == "NewName"
end

"v" is commonly given as the standard name for the value variable, because v is short for value. The value variable is the value of what is inside of the table in the current index. The index variable is just a number, but the value variable can be various things based on what is inside of the table.


Did I answer your question or are you still confused?
Report Abuse
L1kkleC is not online. L1kkleC
Joined: 11 Nov 2011
Total Posts: 961
16 Nov 2014 04:08 PM
Your a great guy! Much clearer now. i and V are just extremely common.

Thanks!
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
16 Nov 2014 04:11 PM
I and V stand for Index and Value, such as when you iterate through
{5, 7, "Hi", workspace, BrickColor.new}
Upon iterating through it, I and V become
1 - 5
2 - 7
3 - "Hi"
4 - game.Workspace
5 - BrickColor.new

K and V stand for Key and Value, such as this.
{ThisKey = 5.2, AnotherKey = 17, ["Hi"] = workspace}
ThisKey - 5.2
AnotherKey - 17
Hi - game.Workspace
Report Abuse
L1kkleC is not online. L1kkleC
Joined: 11 Nov 2011
Total Posts: 961
16 Nov 2014 04:15 PM
Thanks everyone!
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