Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you make a 'table within a table'?

Asked by 7 years ago
local presentMesh = {66887781 = {189748284}, 1237207}

There is an example of what I want, but it doesn't work. I want the "66887781" to equal multiple values, but still be a table. Help, thanks!

2 answers

Log in to vote
4
Answered by 7 years ago
Edited 7 years ago

You could essentially keep as many tables as you want in a table.

Here's an example:

local menu = {
    [1] = {"Burger", 3.50},
    [2] = {"Fries", 2},
    [3] = {"Soda", 1.99}
}

And if you wanted to store multiple tables inside each other, you could do this:

local menu = {
    ["Meals"] = {
        ["Number 1"] = {"Cheeseburger", "Fries", "Drink", 8},
        ["Number 7"] = {"Hamburger", "Fries", "Drink", 7},
        ["Number 18"] = {"Veggie", "Fries", "Drink", 6.50}
    }
}

Hope this helped.

Ad
Log in to vote
1
Answered by 7 years ago

Tables are a what they sound like, a list of values or a table of values. Tables can hold any piece of information, including other tables.

If what your saying is what i think your saying, you would use the following;


table1 = {}

Table 1 is your first table. You can store anything inside of it.


table1 = { table2 = {"Value 1", "Value2"} }

Table 1, contains a table called table 2. Table 2 contains 2 values, value 1 and value 2

Lets say value 1 and value 2 equal, 1 and 2.

table1 = {table2 = { 1 , 2 } }

You can edit the value of 1 and 2 inside of table two by doing the following;

Example1;

table1.table2[1] = 5

Example2;

table1.Table[2] = 8

another example is;

Orange = {Apple = { "Mango" , "Bananna" } } ------------ Very creative ;) lol

Again, you can edit the contents of apple by doing the following;

Orange.Apple[1] = "SomeOtherFruit"

The [1] is the place value of the item within the table, say there are 5 items, and you want to edit the 4th, you would use [4]

Note; From my experience, i may be wrong, for example, table1 = { table2={} }, if you request the number of items within table1, it would return 0 or nil.

In this case,

 table1 = { table2={},"Example"},

it will return 1, a table inside of a table is not counted, but the contents of the 2nd table will be counted for the number of items requested for the seccond table.

One last thing;

Orange = { Apple = {"Banana","Mango"} }

If you want to edit the table, say change Apple to another table, aka the contents of apple you can do the following; Table2 = {"Nothing","Fruits are gross"}

Orange.Apple = Table2

It will return like so;

Orange = { Apple = {"Nothing","Fruits are gross"}}

Sorry for hogging your time, but i'd just thought i'd give you my knowlage on how tables work as it might help out in the future.

0
Lol i feel like something is missing, but it has worked for me since i started using tables, and i constantly use them. Abstract_Life 65 — 7y
0
'table1.table2[key]' is the same as 'table[table2][key]' as it just a different way of indexing tables. This is often comes in handy when working with userdata objects, eg:' 'part.BrickColor == part["BrickColor"]' BlackJPI 2658 — 7y
0
"I'm pretty sure that's not how you index tables" - Why does somebody who knows little about tables try to talk about tables? User#6546 35 — 7y
0
Calm down. I hadn't seen any documentation showing that that was possible so I assumed it wasn't. I did some testing and realized I was wrong, and deleted the comment. No harm done. DepressionSensei 315 — 7y
View all comments (3 more)
0
Now im confused.... am i right or am i wrong? should i have not said this? or are my ways inefficient? damn.. Abstract_Life 65 — 7y
0
@TriickXzoniQ nope, your way works just fine, I was just being an idiot. DepressionSensei 315 — 7y
0
Lol you aren't a idiot, everyone makes mistakes, thanks for telling me though. Abstract_Life 65 — 7y

Answer this question