• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[i]

slp13at420

Mad Scientist
or more to the point `i` is a variable that holds a value of either numerical/alpha-numerical or whatever

Code:
local Table = {
      [1] = "hello I am 1",
      [2] = "hello I am 2",
      [3] = 3,
      [4] = 4,
      [5] = "haha im 5",
      };

	for i = 1, 5 do
	
               	print("i = "..i.." keys to "..Table[i])
	end

in this Lua script above `i` will have a numerical value starting with 1 and increasing to 5
as it loops thru 1 to 5 you will see how Table outputs differently per each loop.

so `i` is being used as a key to access a specific position of stored data.

hope this helps.

oh yea as you get a better understanding of Arrays/tables you will see it does not have to be the letter i , you can use any alpha numerical string as a key as long as it does not conflict with another variable.
e.g. in Guild Warz i use the Guild's name as a key.

--> http://www.cplusplus.com/doc/tutorial/arrays/ <--
this link might help out.

lol and along comes a Tommy lol yea I can do arrays in C++ but i'm faster at Lua :p and the descriptive info you are looking for is the same.
but awwww wheres the fun in yours? it needs sum kewl flashy lights and whistles and fun xD
 
Last edited:

Tommy

Founder
"i" is a value that returns an element from an array.

Example:

Code:
int array[] = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; i++)
    cout << array[i];

Above will print:

1, 2, 3, 4, 5

On a side note: It doesn't necessarily have to be "i". It can be any letter or word you want as long as it doesn't conflict with existing variables or syntax keywords.

For example:

Code:
int array[] = { 1, 2, 3, 4, 5 };
for (int [COLOR="#00FF00"]element[/COLOR] = 0; [COLOR="#00FF00"]element[/COLOR] < 5; [COLOR="#00FF00"]element[/COLOR]++)
    cout << array[[COLOR="#00FF00"]element[/COLOR]];
 
Top