This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
raxteeze's profile picture

How to make a table in a single column?

Started by raxteeze, 02 August 2015 - 05:35 PM
raxteeze #1
Posted 02 August 2015 - 07:35 PM
I have created a table, but it is necessary that it be in a single column rather than several. Help me please.

textutils.tabulate(fs.list('/.root/.system/.acc/'..input2..'/.files/'))
Lyqyd #2
Posted 02 August 2015 - 08:06 PM
Don't use textutils.tabulate to display the table contents if you don't want them tabulated. A simple for loop should do it:


for k, v in ipairs(fs.list('/.root/.system/.acc/'..input2..'/.files/')) do
  print(v)
end
raxteeze #3
Posted 02 August 2015 - 08:08 PM
Don't use textutils.tabulate to display the table contents if you don't want them tabulated. A simple for loop should do it:


for k, v in ipairs(fs.list('/.root/.system/.acc/'..input2..'/.files/')) do
  print(v)
end

Thank you very much :)/>
raxteeze #4
Posted 02 August 2015 - 08:24 PM
Don't use textutils.tabulate to display the table contents if you don't want them tabulated. A simple for loop should do it:


for k, v in ipairs(fs.list('/.root/.system/.acc/'..input2..'/.files/')) do
  print(v)
end

I have a trouble, please, help :(/>



We need indent 3 pixels for each name
Edited on 02 August 2015 - 06:25 PM
MKlegoman357 #5
Posted 02 August 2015 - 08:49 PM
Use term.setCursorPos to set the cursor position to where you want before writing to the screen.
flaghacker #6
Posted 02 August 2015 - 10:00 PM
An easier solution would be to write a coupe of spaces on each line:


for k, v in ipairs(fs.list('/.root/.system/.acc/'..input2..'/.files/')) do
  write ("   ")
  print(v)
end
MKlegoman357 #7
Posted 03 August 2015 - 08:54 AM
An easier solution would be to write a coupe of spaces on each line:


for k, v in ipairs(fs.list('/.root/.system/.acc/'..input2..'/.files/')) do
  write ("   ")
  print(v)
end

That's some really unnecessary computations a computer has to do for as simple task as changing the cursor's position.
raxteeze #8
Posted 03 August 2015 - 09:44 AM
An easier solution would be to write a coupe of spaces on each line:


for k, v in ipairs(fs.list('/.root/.system/.acc/'..input2..'/.files/')) do
  write ("   ")
  print(v)
end

Thank you!
flaghacker #9
Posted 03 August 2015 - 05:47 PM
An easier solution would be to write a coupe of spaces on each line:


for k, v in ipairs(fs.list('/.root/.system/.acc/'..input2..'/.files/')) do
  write ("   ")
  print(v)
end

That's some really unnecessary computations a computer has to do for as simple task as changing the cursor's position.

If the program is 4 lines long and you're simply printing a couple of words to the screen performance is something you really shoudn't be thinking about. Besides, what would your version look like? Something like this?


local _, startY = term.getCursorPos()
for i, v in ipairs(fs.list('/.root/.system/.acc/'..input2..'/.files/')) do
  term.setCursorPos(3, startY + i - 1)
  print(v)
end

That looks about as good to me, if not worse. I don't think it's usefull to worry about these kinds of micro-optimizations.
Edited on 03 August 2015 - 03:48 PM
MKlegoman357 #10
Posted 03 August 2015 - 08:40 PM
I don't think it's usefull to worry about these kinds of micro-optimizations.

It's not about any kind of optimizations. It's about helping OP to become a better programmer. This reminds me of one thing: opening a fridge simply to help navigate the room by turning on it's light, rather than walking a few more meters to turn on the actual light. All I want for the OP is to become a better programmer, by showing a better way of doing things.
TheOddByte #11
Posted 03 August 2015 - 09:16 PM
I have to agree with MKlegoman on this one, it's better to give someone better coding habits from the start, as it's hard to change old habits later on.
People are ultimately here to learn, so why not teach them the best way to do things, instead of the easiest and fastest?