When I run the script, instead of getting "Hmm" output, i get an error: attempt to index field 'Y' (a nil value).
This is my code:
local D = {};
local E = {};
E["Y"].Test = "Hmm"
table.insert(D,E);
print(D[1]["Y"].Test);
When I run the script, instead of getting "Hmm" output, i get an error: attempt to index field 'Y' (a nil value).
This is my code:
local D = {};
local E = {};
E["Y"].Test = "Hmm"
table.insert(D,E);
print(D[1]["Y"].Test);
The code errors because Y doesn't exist, you need to create it before assigning something to it, it's like trying to change the property of something that doesn't exist, first the instance needs to be created in order to be changed.
local D = {};
local E = {};
E.Y = {} -- Create Y
E["Y"].Test = "Hmm"
table.insert(D,E);
print(D[1]["Y"].Test);
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
I see.. thank you! :)