Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does it print the 'v' when i tell it to print 'i' ?

So if i go print(i.." "..v) the i is 1 and the v is whatever is in the table, so why does it print out the v when i go print(table[i])

3 comments

0

Maybe, if you showed the code we'll know why

0

We will need you to post the script for us to understand what is wrong.

0

There is no script to post, i'm just asking on how tables work with the in pairs.

1 answer

✓ Accepted answer

It might be a little clearer if we rewrite

for i,v in pairs(table) do
    print(table[i])
end

as

for index, value in pairs(table) do
    print(table[index])
end

The i or index here refers to the index in table table of value v or value.

Basically, table[i] == v returns true because i is defined that way.

This discussion is preserved as it was. New answers, comments, and votes are closed.