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. Paid developer. Twitter: @willia_am - http://www.williamdasilva.fr
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? Paid developer. Twitter: @willia_am - http://www.williamdasilva.fr
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 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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). Sometimes I dream about cheese
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.) Ingame Name : |DGT|Puma DGT Clan Server 24/7 Owner/Scripter MultiGameMode in progress :
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. Paid developer. Twitter: @willia_am - http://www.williamdasilva.fr
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