Page 1 of 2
Echo a list in a miniconsole
Posted: Thu Aug 12, 2021 4:09 am
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?
Re: Echo a list in a miniconsole
Posted: Thu Aug 12, 2021 2:05 pm
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.
Re: Echo a list in a miniconsole
Posted: Thu Aug 12, 2021 6:54 pm
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
Re: Echo a list in a miniconsole
Posted: Thu Aug 12, 2021 7:01 pm
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.
Re: Echo a list in a miniconsole
Posted: Thu Aug 12, 2021 7:45 pm
by demonnic
nah, just use HelloWorld:echo(table.concat(myTable, "\n"))
Re: Echo a list in a miniconsole
Posted: Thu Aug 12, 2021 7:46 pm
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.
Re: Echo a list in a miniconsole
Posted: Thu Aug 12, 2021 8:02 pm
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.
Re: Echo a list in a miniconsole
Posted: Thu Aug 12, 2021 9:01 pm
by demonnic
None I'm aware of, no.
Re: Echo a list in a miniconsole
Posted: Fri Aug 13, 2021 12:48 am
by Puckster
Well, nothing a little arithmatic and movcurso can't solve, I think ...
Thanks again for the help.
Re: Echo a list in a miniconsole
Posted: Fri Aug 13, 2021 2:23 am
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 (1.4 KiB) Viewed 4329 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 (1.28 KiB) Viewed 4329 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 (1.28 KiB) Viewed 4329 times