Page 1 of 1

Simple table in Labels.

Posted: Sun Jan 26, 2014 9:21 am
by Jaren
I apologize in advance for my ignorance however I looked and looked and something so simple seems to elude me.

How do I print, echo or display a simple table in a label?

I've tried this but it only displays the last key when the entire label is restarted:

Code: Select all

for i, v in ipairs(mytable) do 
  mylabel:echo(v)
end
I'd much rather use a label to display the table but if not, is there an easier way to display it via a miniconsole? I understand the selectCurrentLine, copy and append trick for copying things at the cursor in the main window but no idea how to append things from a stored table.

I also figured out a fancy way to do this with a Hbox but that way took up a ton of cpu processing time, was very bulky to work with and was generally sloppy. Anyways, again I thank you kind folks for any help you can provide. I normally try to find the answer on my own but sometimes these little things cause me to hit a wall.

Re: Simple table in Labels.

Posted: Sun Jan 26, 2014 12:57 pm
by Jor'Mox
For a label, you would need to construct the entire string you want it to display, and then echo it all at once. They aren't designed to display large amounts of text at once.

With a mini console, you can just echo one item, echo a new line "\n", and then echo the next item. Really simple.

Re: Simple table in Labels.

Posted: Sun Jan 26, 2014 8:51 pm
by Akaya
Code: [show] | [select all] lua
local t = {}
for k,v in pairs(mytable) do
  table.insert(t,k..": "..v)
end
mylabel:echo(table.concat(t,"<br>") )
That would echo it all to a label. Each key and value on a new line. But again, if you're doing this often, a miniconsole is the way to go.

Re: Simple table in Labels.

Posted: Mon Jan 27, 2014 12:17 am
by Jaren
Thanks, that worked like a charm. These ideas have given me a few more tools to work with.