local t = {a=1, b=2, c=3} local function check (key) print( t.key ) end print (t.a) ---\> 1 check(a) ---\> nil
Why doesn’t the function work?!
local t = {a=1, b=2, c=3} local function check (key) print( t.key ) end print (t.a) ---\> 1 check(a) ---\> nil
Why doesn’t the function work?!
Hi Abdo23,
You can refer the following:
[lua]
local t = {a=1, b=2, c=3}
for key,value in pairs(t) do
print("key = ", key)
print("value = ", value)
end
[/lua]
_ While in your case:
Kindly
Assif :)
You’ve got that slightly wrong.
Try this:
local t = {a=1, b=2, c=3} local function check (key) print( t[key] ) end print (t.a) ---\> 1 check("a") ---\> 1 check("b") ---\> 2
That works perfectly. Thanks
Hi Abdo23,
You can refer the following:
[lua]
local t = {a=1, b=2, c=3}
for key,value in pairs(t) do
print("key = ", key)
print("value = ", value)
end
[/lua]
_ While in your case:
Kindly
Assif :)
You’ve got that slightly wrong.
Try this:
local t = {a=1, b=2, c=3} local function check (key) print( t[key] ) end print (t.a) ---\> 1 check("a") ---\> 1 check("b") ---\> 2
That works perfectly. Thanks