Lua Tables w/ Changing Variables - Mental Block
- by bottles
I always assumed that changing the value of k from "x" to 20 would eliminate "x". So why then in this example are we able to go back and reference "x"?
a = {}
k = "x"
a[k] = 10
print(a[k]) ---> Returns 10
print(a["x"]) ---> Returns 10
a[20] = "great"
k = 20
print(a[k]) ---> "great"
a["x"] = a["x"] + 1
print(a["x"]) --> 11
Why does that last print command work, and return 11? I thought we set k = 20. Why is "x" even in the picture?