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
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Use a variable in a table name?

Previous Thread :: Next Thread 
Colt324 is not online. Colt324
Joined: 19 Aug 2009
Total Posts: 1562
01 Aug 2012 01:04 PM
So it's basically

number = 8

if I wanted to have a table called table8, but 8 could be changed, what would I do to call the table using the variable as the last character of the table name?
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
01 Aug 2012 01:06 PM
table is just the NAME of the table. The only thing you can do is:

local table = {["number"] = 8}
print(table["number"])

http://wiki.roblox.com/index.php/User:ElectricBlaze
Report Abuse
Colt324 is not online. Colt324
Joined: 19 Aug 2009
Total Posts: 1562
01 Aug 2012 01:09 PM
I'm not asking about assigning a number to a table.
Rather, I'm talking about the table name (variable)
I need the variable to be called by some textm "table" in my example, and then a number.
So if the number I wanted was 8, then the table would be
table8 = {}
or if the number was 2
table2 = {}
Report Abuse
Colt324 is not online. Colt324
Joined: 19 Aug 2009
Total Posts: 1562
01 Aug 2012 01:15 PM
bump
Report Abuse
L2000 is not online. L2000
Joined: 03 Apr 2008
Total Posts: 77448
01 Aug 2012 01:16 PM
That wouldn't be possible like that. However, an alternative could be to place it into a table, with the given number being the table:

local myTable = { };
local number = 8;
myTable[number] = { }

Which, although not exactly what you'd want, could work in the same way. To find it, instead of saying table8 in the script, you'd say:
myTable[8]
Or, using the number variable:
myTable[number]
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
01 Aug 2012 01:17 PM
number = 1337
getfenv()["table".. number] = {}
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
01 Aug 2012 01:20 PM
@L2000 - Actually, it is possible. With the getfenv function.

    for i = 1, 8 do
        getfenv()["table" .. i] = {}
    end

Now you can do:

    print(table1)
    print(table2)
    print(table3)
    print(table4)
    print(table5)
    print(table6)
    print(table7)
    print(table8)

http://wiki.roblox.com/index.php/User:ElectricBlaze
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
01 Aug 2012 01:20 PM
SU8, HOW DARE YOU EARLY POST ME!

http://wiki.roblox.com/index.php/User:ElectricBlaze
Report Abuse
Colt324 is not online. Colt324
Joined: 19 Aug 2009
Total Posts: 1562
01 Aug 2012 01:21 PM
Thanks to both su8 and ElectricBlaze.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
01 Aug 2012 01:21 PM
No problem. :)

http://wiki.roblox.com/index.php/User:ElectricBlaze
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
01 Aug 2012 01:21 PM
>SU8, HOW DARE YOU EARLY POST ME!

how dare you late post me?
:PPP
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
01 Aug 2012 01:23 PM
nooo cuz latepotsing is normal and we hz to do abnormla stoof!11111111!1111!!!!!!!!!!!!!!!111oneone!111!!!!!!!!!!!!!!11111!!twoeleven!1

http://wiki.roblox.com/index.php/User:ElectricBlaze
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