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

[Question] Monitor text help!

Started by Relk, 04 January 2013 - 06:36 AM
Relk #1
Posted 04 January 2013 - 07:36 AM
Hi, the server that I am a mod on right now has a staff list board, the code used for it now is this.


local tText = {
"---Owner---",
"name",
" ",
"---Administrator---",
"name",
" ",
"---Moderators---",
"name",
"name",
"name",
"name",
"name",
"name",
"name",
"name"

}
local sSide = "left"
local nTextSize = 1
local function printCenter(mon, t)
local w, h = mon.getSize()
local y = math.floor((h / 2) - (#t / 2)) - 1
for i, line in ipairs(t) do
local x = math.floor((w / 2) - (#line / 2))
mon.setCursorPos(x, y + i)
mon.write(line)
end
end
local mon = peripheral.wrap(sSide)
mon.setTextScale(nTextSize)
printCenter(mon, tText)

Problem is now, I need to add a couple more people, but the list is too long and it cuts off some of it. So I was thinking of maybe making 2 separate columns for the moderators list, but I really don't know how to.
FUCKCOMPUTERCRAFT!"£ #2
Posted 04 January 2013 - 07:38 AM
I could offer a suggestion on how to do this, but it wouldn't be using tables is that ok?
Relk #3
Posted 04 January 2013 - 07:40 AM
I could offer a suggestion on how to do this, but it wouldn't be using tables is that ok?

Sure, go for it. Anything would help.
FUCKCOMPUTERCRAFT!"£ #4
Posted 04 January 2013 - 07:42 AM
I'll write a program for you. A few questions is it an advantage monitor and or computer and does the server have http enabled…?
Relk #5
Posted 04 January 2013 - 07:49 AM
Not really sure what you mean but I am using a big monitor attached to a computer, there is also no http enabled.
Bubba #6
Posted 04 January 2013 - 07:49 AM
Tables are really the best way to go about this. What this program does is write all of the items in tText until it reaches then bottom of the screen, whereupon it adds 20 to the xValue which it is writing at and resets the yValue to 1.


local monitor = peripheral.wrap("left")
local yValue = 1
local xValue = 1
local xSize, ySize = monitor.getSize()
local function writeAt(text)
  monitor.setCursorPos(xValue, yValue)
  monitor.write(text)
  if yValue == ySize then
	 yValue = 1
	 xValue = xValue + 20
  else
	 yValue = yValue + 1
  end
end
for i=1, #tText do
  writeAt(tText[i])
end

Edit: Added monitor support and moved the next column over more.
FUCKCOMPUTERCRAFT!"£ #7
Posted 04 January 2013 - 07:50 AM
okay is it tekkit?

NVM ^^^ he got it
Relk #8
Posted 04 January 2013 - 07:51 AM
Yes.
FUCKCOMPUTERCRAFT!"£ #9
Posted 04 January 2013 - 08:13 AM
Use the above^^^
Bubba

​sorted it.. :)/>
Relk #10
Posted 04 January 2013 - 09:04 AM
Tables are really the best way to go about this. What this program does is write all of the items in tText until it reaches then bottom of the screen, whereupon it adds 20 to the xValue which it is writing at and resets the yValue to 1.


local monitor = peripheral.wrap("left")
local yValue = 1
local xValue = 1
local xSize, ySize = monitor.getSize()
local function writeAt(text)
  monitor.setCursorPos(xValue, yValue)
  monitor.write(text)
  if yValue == ySize then
	 yValue = 1
	 xValue = xValue + 20
  else
	 yValue = yValue + 1
  end
end
for i=1, #tText do
  writeAt(tText[i])
end

Edit: Added monitor support and moved the next column over more.

Thanks a lot, it worked for me but I want it centered, I am having trouble doing that, can you help me?
Bubba #11
Posted 04 January 2013 - 09:20 AM
Thanks a lot, it worked for me but I want it centered, I am having trouble doing that, can you help me?

Sure. You want it centered in the column I'm guessing? Try this.


local monitor = peripheral.wrap("left")
local xSize, ySize = monitor.getSize()
local xValue = 0
local yValue = 1


local function writeAt(text)
  monitor.setCursorPos((10+xValue)/2-(#text/2), yValue) --Half of the column size + the starting xValue - half of the text length
  monitor.write(text)
  if yValue == ySize then
         yValue = 1
         xValue = xValue + 20
  else
         yValue = yValue + 1
  end
end

for i=1, #tText do
  writeAt(tText[i])
end
end
remiX #12
Posted 04 January 2013 - 09:25 AM
If the monitor is big enough then change the monitor.setCursorPos() to this:

monitor.setCursorPos( (xSize - #text)/2, yValue)
Bubba #13
Posted 04 January 2013 - 09:27 AM
If the monitor is big enough then change the monitor.setCursorPos() to this:

monitor.setCursorPos( (#text - xSize)/2, yValue)

That won't print it centered in the column though, just centered in the xSize area. And I think you messed up a bit with the #text - xSize part because the length of text will always be shorter than xSize, meaning that you'd have a negative number.
Relk #14
Posted 04 January 2013 - 09:37 AM
Thanks a lot, it worked for me but I want it centered, I am having trouble doing that, can you help me?

Sure. You want it centered in the column I'm guessing? Try this.


local monitor = peripheral.wrap("left")
local xSize, ySize = monitor.getSize()
local xValue = 0
local yValue = 1


local function writeAt(text)
  monitor.setCursorPos((10+xValue)/2-(#text/2), yValue) --Half of the column size + the starting xValue - half of the text length
  monitor.write(text)
  if yValue == ySize then
		 yValue = 1
		 xValue = xValue + 20
  else
		 yValue = yValue + 1
  end
end

for i=1, #tText do
  writeAt(tText[i])
end
end

Getting this error.

FUCKCOMPUTERCRAFT!"£ #15
Posted 04 January 2013 - 09:37 AM

function cPrint( text )
	    -- prints in the centre of the current line.
	    -- Z is just their to stop errors
	    local z,y = term.getCursorPos()
	    local x,z = term.getSize()
	    local textL = string.len(text)
	    local xCor = x/2 - textL/2
	    term.setCursorPos(xCor, y)
	    print(text)
end  

This is what I use to have the text begin from the centre…. Taken from my GUI functions
remiX #16
Posted 04 January 2013 - 09:43 AM
Relk, remove the very last line (end) of your code
Bubba #17
Posted 04 January 2013 - 09:46 AM
Getting this error.


Could you tell me what is on line 42? I just tried the code and it works fine for me. Just in case the code in the code box code box got fudged somehow, here it is again.

local yValue = 1
local xValue = 1
local xSize, ySize = term.getSize()
local function writeAt(text)
  term.setCursorPos((10+xValue)/2-(#text/2), yValue)
  term.write(text)
  if yValue == ySize then
	 yValue = 1
	 xValue = xValue + 20
  else
	 yValue = yValue + 1
  end
end
for i=1, #tText do
  writeAt(tText[i])
end


function cPrint( text )
		-- prints in the centre of the current line.
		-- Z is just their to stop errors
		local z,y = term.getCursorPos()
		local x,z = term.getSize()
		local textL = string.len(text)
		local xCor = x/2 - textL/2
		term.setCursorPos(xCor, y)
		print(text)
end  

This is what I use to have the text begin from the centre…. Taken from my GUI functions

You have a similar problem to the one Remix had; you're still printing from the center of the page, not the column.
Bubba #18
Posted 04 January 2013 - 09:47 AM
Relk, remove the very last line (end) of your code

Ahh. Now looking at the code I see that extra end there. Yeah remove that and it should be good to go.
Relk #19
Posted 04 January 2013 - 09:49 AM
Relk, remove the very last line (end) of your code

Ok, it is now showing like this.



Now, how do I move the whole thing to the middle now?
remiX #20
Posted 04 January 2013 - 09:49 AM
You have a similar problem to the one Remix had; you're still printing from the center of the page, not the column.

Well, he asked how to center the code so I showed him how to center it on the screen, but like I said, if the monitor is big enough.

Edit: Just saw your post now, change

term.setCursorPos((10+xValue)/2-(#text/2), yValue)
to
term.setCursorPos((xSize - #text)/2, yValue)
Bubba #21
Posted 04 January 2013 - 09:52 AM
-snip- Double post for some reason
Relk #22
Posted 04 January 2013 - 09:56 AM
Thanks for the help everyone! Worked perfectly!
Bubba #23
Posted 04 January 2013 - 09:56 AM
Okay I'm confused now. I thought that there were too many entries for it all to fit on one line. The issue with just printing it centered is that if it continues onto the next line, some text will be overwritten.

Edit: OP's problem is solved so nevermind
Relk #24
Posted 04 January 2013 - 09:57 AM
Okay I'm confused now. I thought that there were too many entries for it all to fit on one line. The issue with just printing it centered is that if it continues onto the next line, some text will be overwritten.

That was the main issue, but I put your code in and it worked, but it was not centered.
FUCKCOMPUTERCRAFT!"£ #25
Posted 04 January 2013 - 10:05 AM
Getting this error.


Could you tell me what is on line 42? I just tried the code and it works fine for me. Just in case the code in the code box code box got fudged somehow, here it is again.

local yValue = 1
local xValue = 1
local xSize, ySize = term.getSize()
local function writeAt(text)
  term.setCursorPos((10+xValue)/2-(#text/2), yValue)
  term.write(text)
  if yValue == ySize then
	 yValue = 1
	 xValue = xValue + 20
  else
	 yValue = yValue + 1
  end
end
for i=1, #tText do
  writeAt(tText[i])
end


function cPrint( text )
		-- prints in the centre of the current line.
		-- Z is just their to stop errors
		local z,y = term.getCursorPos()
		local x,z = term.getSize()
		local textL = string.len(text)
		local xCor = x/2 - textL/2
		term.setCursorPos(xCor, y)
		print(text)
end  

This is what I use to have the text begin from the centre…. Taken from my GUI functions

You have a similar problem to the one Remix had; you're still printing from the center of the page, not the column.

Yes my code centres it as you wanted… Just now do cPrint("NAME < FEW SPACES> NAME") You can make it appear like coloums by just putting spaces….
Loki #26
Posted 04 January 2013 - 11:12 AM
Thanks a lot, it worked for me but I want it centered, I am having trouble doing that, can you help me?

Sure. You want it centered in the column I'm guessing? Try this.


local monitor = peripheral.wrap("left")
local xSize, ySize = monitor.getSize()
local xValue = 0
local yValue = 1


local function writeAt(text)
  monitor.setCursorPos((10+xValue)/2-(#text/2), yValue) --Half of the column size + the starting xValue - half of the text length
  monitor.write(text)
  if yValue == ySize then
		 yValue = 1
		 xValue = xValue + 20
  else
		 yValue = yValue + 1
  end
end

for i=1, #tText do
  writeAt(tText[i])
end
end

Getting this error.

Damn that pentagon is hypnotising me like crazy!…Just saying <_</>
remiX #27
Posted 04 January 2013 - 08:24 PM

x0pk1n can you post the full code so we can find the error.