• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved pairs key

GOD Wille

Excellent OT User
Joined
Jan 11, 2010
Messages
2,826
Solutions
2
Reaction score
815
Location
Sweden
Is it any way I can access array Y key with index from array x, if the index name is the same on the both of them?

Example of what I'm thinking, that doesn't work;
Code:
local arrx = {b = 1, c = 2}
local arry = {b = 2, c = 1}

for i,k in pairs(arrx) do
print(arry.k)
end
 
Solution
Is it any way I can access array Y key with index from array x, if the index name is the same on the both of them?

Example of what I'm thinking, that doesn't work;
Code:
local arrx = {b = 1, c = 2}
local arry = {b = 2, c = 1}

for i,k in pairs(arrx) do
print(arry.k)
end

Doesn't work because you're checking for value k (arry.k) when you're supposed to be looking for index i.
Run this and see what happens:

Lua:
local arrx = {b = 1, c = 2}
local arry = {b = 3, c = 4}
for k,v in pairs(arrx) do
print("Checking index " ..k.. ". In array X["..k.."] is "..arrx[k].." | In array Y["..k.."] is "..arry[k])
end

Or in your script, replace arry.k with
Code:
arry[i]
Is it any way I can access array Y key with index from array x, if the index name is the same on the both of them?

Example of what I'm thinking, that doesn't work;
Code:
local arrx = {b = 1, c = 2}
local arry = {b = 2, c = 1}

for i,k in pairs(arrx) do
print(arry.k)
end

Doesn't work because you're checking for value k (arry.k) when you're supposed to be looking for index i.
Run this and see what happens:

Lua:
local arrx = {b = 1, c = 2}
local arry = {b = 3, c = 4}
for k,v in pairs(arrx) do
print("Checking index " ..k.. ". In array X["..k.."] is "..arrx[k].." | In array Y["..k.."] is "..arry[k])
end

Or in your script, replace arry.k with
Code:
arry[i]
 
Solution
Back
Top