Thread Tools Display Modes
07-04-11, 07:15 AM   #1
mazuliite
A Defias Bandit
Join Date: Feb 2009
Posts: 2
Basic lua code question.

Hello dear fellas,

I've got a question on how do I insert these variables into a table and then print the tables content, as with this code that I've got so far it doesn't seem to return anything when I try to print it out.

Code:
local channels = {}
table.insert(channels, {id1, name1, id2, name2, ... = GetChannelList()});

print(channels);
Thank you for your time and help in advance.
  Reply With Quote
07-04-11, 07:27 AM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
I'm not sure on this, however I do think printing 'channels' will simply return the table rather than the contents of the table. This should work (although the rest of the code still throws an error):

Code:
for i = 1, #channels do
	print(channels[i])
end
  Reply With Quote
07-04-11, 08:43 AM   #3
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
afaik, there a different ways to do this, and I think it really depends on what exactly you want to do ..
Code:
for i, v in ipairs({GetChannelList()}) do
	print(i, v)
end
Code:
local channels = {}

for i = 1, #{GetChannelList()} do
	channels[i] = select(i, GetChannelList())
	print(i, channels[i])
end
Code:
local channels = {}

for i = 1, MAX_CHANNEL_BUTTONS do
	tinsert(channels, (select(i, GetChannelList())))
end

for i = 1, #channels do
	print(i, channels[i])
end
Code:
local channels = {GetChannelList()}

for i, v in ipairs({channels()}) do
	print(i, v)
end

Last edited by Ketho : 07-05-11 at 04:39 AM.
  Reply With Quote
07-04-11, 08:52 AM   #4
mazuliite
A Defias Bandit
Join Date: Feb 2009
Posts: 2
Now that's an support.
Didn't hope to get a reply this fast.
Thank you very much guys for your help, the right one for me was Kethos 2nd code chunk. Now If I could find where or how to give you guys some honor/respect forum points I'd definitely do it.

Appreciated!
  Reply With Quote
07-04-11, 04:21 PM   #5
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Just want to say. I'm just not sure what you want, so I just posted random stuff :/

You asked to print out a table's contents, Haleth's example is the answer for your question :s

Last edited by Ketho : 07-05-11 at 03:20 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Basic lua code question.


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