L2000
|
  |
| Joined: 03 Apr 2008 |
| Total Posts: 77448 |
|
|
| 25 May 2012 08:05 PM |
I have two tables, a and b, like so:
local a = {"Value"} local b = {"Value1"}
Now, I want to insert a into b, so I do this: table.insert(b, a) print(b[2][1]) > Value
However, I want to run this :
print(b["a"][1])
From the table.insert(). Is this possible? |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 25 May 2012 08:12 PM |
Well, if you do:
print(b["a"][1])
That will print a's 1. Lemme try. :D
MrMcAero |
|
|
| Report Abuse |
|
|
200AB
|
  |
| Joined: 24 Aug 2010 |
| Total Posts: 1604 |
|
|
| 25 May 2012 08:13 PM |
Just do something like this:
local b = {[1] = "Value"} b["a"] = {[1] = "Value1"}
and you can do.. print(b[1],b["a"][1]) >Value Value1 |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 25 May 2012 08:13 PM |
This works:
b = {["a"]={"ABC"}} -- Dictionary. print(b["a"][1]) > ABC
MrMcAero |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 25 May 2012 08:14 PM |
This also works.
b = {a={"ABC"}} print(b["a"][1])
> ABC
MrMcAero |
|
|
| Report Abuse |
|
|
L2000
|
  |
| Joined: 03 Apr 2008 |
| Total Posts: 77448 |
|
|
| 25 May 2012 08:18 PM |
@200 I'm thinking of doing something where I get everything in game through that, then make tables to insert everything into there. Would that script work for the following code as well?
local b,tab = { } for i,v in pairs(game:GetChildren()) do tab = {[v.Name] = "Test"} table.insert(tab, b) end
print(b[game:GetChildren()[1].Name]) |
|
|
| Report Abuse |
|
|
200AB
|
  |
| Joined: 24 Aug 2010 |
| Total Posts: 1604 |
|
|
| 25 May 2012 08:26 PM |
>@200 >I'm thinking of doing something where I get everything in game through that, then make tables to insert everything into there. Would that script work for the following code as well? >local b,tab = { } >for i,v in pairs(game:GetChildren()) do >tab = {[v.Name] = "Test"} >table.insert(tab, b) >end >print(b[game:GetChildren()[1].Name])
I wouldn't use table.insert to insert other tables into a table, I would just manually declare them, and only use table.insert for values. |
|
|
| Report Abuse |
|
|
L2000
|
  |
| Joined: 03 Apr 2008 |
| Total Posts: 77448 |
|
|
| 25 May 2012 08:44 PM |
@200 I'd manually declare them, but that would make it harder to find them; in a table, I can have it like this: tab[object.Name] And edit it with that, instead of having to try to find what the variable was declared as.
Though, this seems to work, so I can make what I'd like to with it. |
|
|
| Report Abuse |
|
|