Jump to content

Using sub-tables ?


Miika

Recommended Posts

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"}; 
} 

Link to comment

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"}, 
    } 
} 

Link to comment

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!

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...