generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Inserting Named Tables Into Other Tables?

Previous Thread :: Next Thread 
L2000 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image