Thread Tools Display Modes
07-12-10, 11:11 PM   #1
freight86
A Kobold Labourer
Join Date: Jul 2010
Posts: 1
lua table names.

I am kinda a lua nuub but, I want to do something like this:

number=1
If something~= nothing then
number=number+1
tbl=(tbl..number) (Basically, I want to make this be called tbl2 and the next table be calloed tbl3 and so on.)
tbl={
["a"]=ab,
["b"]=bc,
...

So, I want to know if that is possible to have a variable put into a table name to make the table unique for each if, then function.

Thanks.

Last edited by freight86 : 07-12-10 at 11:12 PM. Reason: added more notes
  Reply With Quote
07-13-10, 06:48 AM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
You mean something like this?

Code:
tbl = 	{
	["a1"] = "entry1",
	["a2"] = "entry2",
	["a3"] = "entry3",
	}

for x = 1, 3 do
	DEFAULT_CHAT_FRAME:AddMessage(tbl["a"..x])
end
Have you seen http://www.lua.org/pil/2.5.html?
  Reply With Quote
07-13-10, 06:48 AM   #3
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
You could use sub-tables (tables inside tables):

Code:
local myTables = {}

local i = 0
if something then
    i = i + 1
    myTables[i] = {
        ["a"] = ab,
        ["b"] = bc,
    }
end

-- You can then access the table via
myTables[1] and so on
EDIT: Duugu was faster :O
__________________
« Website | GitHub »

Oh hai!

Last edited by xConStruct : 07-13-10 at 06:52 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » lua table names.


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off