FatalTerror Posted August 10, 2013 Posted August 10, 2013 Hi there, I wanted to know, how to access to a table value when I'm already on that table. Like this: myTable = { a = {test = "ok"}, b = {test = myTable.a.test} } As you can see, the myTable.b is trying to access to myTable.a but he can't access to this because it's on the same var. How can I do that? If it's possible? Thanks for any help. Regards, FatalTerror.
relief Posted August 10, 2013 Posted August 10, 2013 How about doing it this way: myTable = {} myTable.a = {test = "ok"} myTable.b = {test = myTable.a.test}
FatalTerror Posted August 10, 2013 Author Posted August 10, 2013 How about doing it this way: myTable = {} myTable.a = {test = "ok"} myTable.b = {test = myTable.a.test} Yes but personaly, I really don't want to write an entire file with this method. Sure that my way isn't possible?
Moderators IIYAMA Posted August 10, 2013 Moderators Posted August 10, 2013 myTable = { a = {test = "ok"} } myTable.b = {} myTable.b.test = myTable.a.test outputChatBox(tostring(myTable.a.test)) outputChatBox(tostring(myTable.b.test)) no it isn't, cause you can't index something that hasn't been created yet. myTable = { -- not yet created } -- created
denny199 Posted August 10, 2013 Posted August 10, 2013 It doesn't work because the table isn't loaded yet. Tested it serveral times and this will output "okay" after that i realised that the table isn't loaded yet derptest = "okey" myTable = { a = {test = "okTESTA"}, b = {test = derptest} } addCommandHandler ( "derp", function () outputChatBox ( myTable.b.test ) end) edit: as IIYAMA says (really can't typ that name).
bandi94 Posted August 10, 2013 Posted August 10, 2013 Yes but personaly, I really don't want to write an entire file with this method. Sure that my way isn't possible? Well loop's are a solution. If not a txt generator made in (c/c++) is an another option (if you don't wanna use the loop's on every resource start.)
FatalTerror Posted August 10, 2013 Author Posted August 10, 2013 I was thinking something like "this" from OOP exists for LUA tables. Anyway, thanks everybody for answers.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now