Simple table in Labels.

Post Reply
Jaren
Posts: 31
Joined: Sun Nov 17, 2013 1:55 pm

Simple table in Labels.

Post 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.

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Simple table in Labels.

Post 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.

User avatar
Akaya
Posts: 414
Joined: Thu Apr 19, 2012 1:36 am

Re: Simple table in Labels.

Post 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.

Jaren
Posts: 31
Joined: Sun Nov 17, 2013 1:55 pm

Re: Simple table in Labels.

Post by Jaren »

Thanks, that worked like a charm. These ideas have given me a few more tools to work with.

Post Reply