Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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])

0
Maybe, if you showed the code we'll know why cringe_worthey 97 — 5y
0
We will need you to post the script for us to understand what is wrong. User#21908 42 — 5y
0
There is no script to post, i'm just asking on how tables work with the in pairs. nikki9dor 28 — 5y

1 answer

Log in to vote
1
Answered by
fredfishy 833 Moderation Voter
5 years ago

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.

Ad

Answer this question