Miika Posted April 3, 2016 Posted April 3, 2016 Hi, I just started working with vehicle tuning garage script. I want to make dx navigation so i need to use sub tables to make it easier. How can i use values from sub tables, if my table looks something like this: table = { "Exhaust", {"1018", "1019", "1020", "1021", "1022"}; {"exh_b_ts", "exh_b_t", "exh_b_l", "exh_b_m", "exh_b_s"}; {"Upswept", "Twin", "Large", "Medium", "Small"}; "Rims" {"1025", "1073", "1074", "1075"}; {"wheel_or1", "wheel_sr6", "wheel_sr3", "wheel_sr2"}; {"Offroad", "Shadow", "Mega", "Rimshine"}; }
Anubhav Posted April 3, 2016 Posted April 3, 2016 Something like this: table = { ["Exhaust"]={{"1018,"10913"}}, ["Rims"]={{"1025"}}, Just an example. Can be accessed by: table['Exhaust'][1] will return 1018
Noki Posted April 3, 2016 Posted April 3, 2016 As we know, a table is made up of two things, a key and a value, where a key corresponds to a value. Let's use your table as an example. table = { ["Exhaust"] = { {"1018", "1019", "1020", "1021", "1022"}; {"exh_b_ts", "exh_b_t", "exh_b_l", "exh_b_m", "exh_b_s"}; {"Upswept", "Twin", "Large", "Medium", "Small"} }, ["Rims"] = { {"1025", "1073", "1074", "1075"} {"wheel_or1", "wheel_sr6", "wheel_sr3", "wheel_sr2"} {"Offroad", "Shadow", "Mega", "Rimshine"} } } If I want to print the first value of the third table in Exhaust, I would do: outputDebugString(table["Exhaust"][3][1]) That produces -> "Upswept" Don't see your problem as one big complex problem, break it down into smaller problems. Doing 'table["Exhaust"]' just gives me another table, which has 3 sub tables in that (each identified by a number (1, 2 or 3)). If I do 'table["Exhaust"][3]' I also get another table. But now I have values that correspond to strings. Of course, you can make your table a bit easier to navigate by using each item type as a key that corresponds to a value. table = { ["Exhaust"] = { ["1018"] = {"exh_b_ts", "Upswept"}, } }
Miika Posted April 3, 2016 Author Posted April 3, 2016 As we know, a table is made up of two things, a key and a value, where a key corresponds to a value. Let's use your table as an example. table = { ["Exhaust"] = { {"1018", "1019", "1020", "1021", "1022"}; {"exh_b_ts", "exh_b_t", "exh_b_l", "exh_b_m", "exh_b_s"}; {"Upswept", "Twin", "Large", "Medium", "Small"} }, ["Rims"] = { {"1025", "1073", "1074", "1075"} {"wheel_or1", "wheel_sr6", "wheel_sr3", "wheel_sr2"} {"Offroad", "Shadow", "Mega", "Rimshine"} } } If I want to print the first value of the third table in Exhaust, I would do: outputDebugString(table["Exhaust"][3][1]) That produces -> "Upswept" Don't see your problem as one big complex problem, break it down into smaller problems. Doing 'table["Exhaust"]' just gives me another table, which has 3 sub tables in that (each identified by a number (1, 2 or 3)). If I do 'table["Exhaust"][3]' I also get another table. But now I have values that correspond to strings. Of course, you can make your table a bit easier to navigate by using each item type as a key that corresponds to a value. table = { ["Exhaust"] = { ["1018"] = {"exh_b_ts", "Upswept"}, } } Thank you, this tutorial helped me alot!
Noki Posted April 3, 2016 Posted April 3, 2016 #table["Exhaust"] The # operator is used to find the length of strings and tables with integer keys.
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