Jump to content




[Question] Monitor text help!


  • You cannot reply to this topic
26 replies to this topic

#1 Relk

  • New Members
  • 9 posts

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.

#2 FUCKCOMPUTERCRAFT!"£

  • Validating
  • 87 posts
  • LocationBasement

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?

#3 Relk

  • New Members
  • 9 posts

Posted 04 January 2013 - 07:40 AM

View Postx0pk1n, on 04 January 2013 - 07:38 AM, said:

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.

#4 FUCKCOMPUTERCRAFT!"£

  • Validating
  • 87 posts
  • LocationBasement

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

#5 Relk

  • New Members
  • 9 posts

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.

#6 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

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.

#7 FUCKCOMPUTERCRAFT!"£

  • Validating
  • 87 posts
  • LocationBasement

Posted 04 January 2013 - 07:50 AM

okay is it tekkit?

NVM ^^^ he got it

#8 Relk

  • New Members
  • 9 posts

Posted 04 January 2013 - 07:51 AM

Yes.

#9 FUCKCOMPUTERCRAFT!"£

  • Validating
  • 87 posts
  • LocationBasement

Posted 04 January 2013 - 08:13 AM

Use the above^^^
Bubba

​sorted it.. :)

#10 Relk

  • New Members
  • 9 posts

Posted 04 January 2013 - 09:04 AM

View PostBubba, on 04 January 2013 - 07:49 AM, said:

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?

#11 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 04 January 2013 - 09:20 AM

View PostRelk, on 04 January 2013 - 09:04 AM, said:

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


#12 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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)


#13 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 04 January 2013 - 09:27 AM

View PostremiX, on 04 January 2013 - 09:25 AM, said:

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.

#14 Relk

  • New Members
  • 9 posts

Posted 04 January 2013 - 09:37 AM

View PostBubba, on 04 January 2013 - 09:20 AM, said:

View PostRelk, on 04 January 2013 - 09:04 AM, said:

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.

Posted Image

#15 FUCKCOMPUTERCRAFT!"£

  • Validating
  • 87 posts
  • LocationBasement

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

#16 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 04 January 2013 - 09:43 AM

Relk, remove the very last line (end) of your code

#17 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 04 January 2013 - 09:46 AM

View PostRelk, on 04 January 2013 - 09:37 AM, said:

Getting this error.

Posted Image

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

View Postx0pk1n, on 04 January 2013 - 09:37 AM, said:

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.

#18 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 04 January 2013 - 09:47 AM

View PostremiX, on 04 January 2013 - 09:43 AM, said:

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.

#19 Relk

  • New Members
  • 9 posts

Posted 04 January 2013 - 09:49 AM

View PostremiX, on 04 January 2013 - 09:43 AM, said:

Relk, remove the very last line (end) of your code

Ok, it is now showing like this.

Posted Image

Now, how do I move the whole thing to the middle now?

#20 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 04 January 2013 - 09:49 AM

View PostBubba, on 04 January 2013 - 09:46 AM, said:

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)






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users