Echo a list in a miniconsole

Puckster
Posts: 24
Joined: Fri Jul 30, 2021 11:51 pm

Echo a list in a miniconsole

Post by Puckster »

Is there a way to echo an entire list (table) to a miniconsole other than parsing the list and sending the elements individually?

User avatar
demonnic
Posts: 767
Joined: Sat Dec 05, 2009 3:19 pm

Re: Echo a list in a miniconsole

Post by demonnic »

You can use table.concat to turn the list into a string. table.concat(myTbl, ", ") will produce "This, that, the other' if the table is { "this", "that", "the other" }

Alternately, if you're just looking for a quick dump you can use myMiniConsole:display(myTbl) if it's a Geyser miniconsole.

Puckster
Posts: 24
Joined: Fri Jul 30, 2021 11:51 pm

Re: Echo a list in a miniconsole

Post by Puckster »

Thanks for the response!

That worked, but not quite as desired (though probably as expected ... :-))

myTable = {"1", "2"}
HelloWorld:display(myTable)

results in {"1","2"} being echoed to the miniconsole.

What I was hoping for was

1
2

Puckster
Posts: 24
Joined: Fri Jul 30, 2021 11:51 pm

Re: Echo a list in a miniconsole

Post by Puckster »

By the way, I am guessing the answer is parsing the list and sending the output one item at a time, but I am concerned about the overhead/efficiency of that.

User avatar
demonnic
Posts: 767
Joined: Sat Dec 05, 2009 3:19 pm

Re: Echo a list in a miniconsole

Post by demonnic »

nah, just use HelloWorld:echo(table.concat(myTable, "\n"))

User avatar
demonnic
Posts: 767
Joined: Sat Dec 05, 2009 3:19 pm

Re: Echo a list in a miniconsole

Post by demonnic »

That being said unless you're echoing out tables with thousands of items every prompt or something you should be fine doing the processing yourself.

Puckster
Posts: 24
Joined: Fri Jul 30, 2021 11:51 pm

Re: Echo a list in a miniconsole

Post by Puckster »

Well, a dozen maybe, so ... :-). I have a couple of different options now, though. Thank you!

One last question, is there any way to have the echo start at the bottom of the miniConsole and work up? I think I can figure a way around this wiht 'moveCursor', but thought I would ask.

User avatar
demonnic
Posts: 767
Joined: Sat Dec 05, 2009 3:19 pm

Re: Echo a list in a miniconsole

Post by demonnic »

None I'm aware of, no.

Puckster
Posts: 24
Joined: Fri Jul 30, 2021 11:51 pm

Re: Echo a list in a miniconsole

Post by Puckster »

Well, nothing a little arithmatic and movcurso can't solve, I think ...

Thanks again for the help.

Puckster
Posts: 24
Joined: Fri Jul 30, 2021 11:51 pm

Re: Echo a list in a miniconsole

Post by Puckster »

Interestingly, insertText reverses the order. Here is a comparison:

Code: Select all

myTable = {"zzz", "1", "2", "Bananna", "f", "GGG"}
clearWindow("HelloWorld")
--moveCursor("HelloWorld", 0, 5)
--moveCursorDown("HelloWorld", 5, false)
for _, v in ipairs(myTable) do
  --insertText("HelloWorld", _ .. " " .. v .. "\n")
  echo("HelloWorld", _ .. " " .. v .. "\n")
end
Echo.PNG
Echo.PNG (1.4 KiB) Viewed 221 times

Code: Select all

myTable = {"zzz", "1", "2", "Bananna", "f", "GGG"}
clearWindow("HelloWorld")
--moveCursor("HelloWorld", 0, 5)
--moveCursorDown("HelloWorld", 5, false)
for _, v in ipairs(myTable) do
  insertText("HelloWorld", _ .. " " .. v .. "\n")
  --echo("HelloWorld", _ .. " " .. v .. "\n")
end
Insert.PNG
Insert.PNG (1.28 KiB) Viewed 221 times
But I can't get moveCursor to work:

Code: Select all

myTable = {"zzz", "1", "2", "Bananna", "f", "GGG"}
clearWindow("HelloWorld")
moveCursor("HelloWorld", 0, 5)
--moveCursorDown("HelloWorld", 5, false)
for _, v in ipairs(myTable) do
  insertText("HelloWorld", _ .. " " .. v .. "\n")
  --echo("HelloWorld", _ .. " " .. v .. "\n")
end
Insert.PNG
Insert.PNG (1.28 KiB) Viewed 221 times

Post Reply