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

Monitor text

Started by Swam_, 21 September 2015 - 09:43 PM
Swam_ #1
Posted 21 September 2015 - 11:43 PM
Ok, im a noob. So i need someones help to create a program and explain it so that i can print some text on a monitor. Unfortunatly i dont have any code right now because a friend deleted all of it. I would like for it to ouput to the monitor below it with the following text:
———————————-

Welcome To

Swam's Shop of Destiny

———————————-

Also mabey a bit more centered, and i want the lines to go all the way across.

PS Im useing the version that Tekkit Classic uses so no advanced monitors
TYKUHN2 #2
Posted 22 September 2015 - 08:09 PM

local h, w = term.getSize
local monitor = peripheral.wrap(sideMonitorisON)
monitor.setCursorPos(1,1)
monitor.write(string.rep("-", w))
monitor.setCursorPos(1, 7)
monitor.write(string.rep("-", w))

As for the printing centered there are a a few people who published small sections of code that have that, and I use one from someone else so I would prefer not to share it on his behalf.
Edited on 22 September 2015 - 06:09 PM
Dustmuz #3
Posted 22 September 2015 - 08:14 PM
for center text :)/>


function center (text)
  x, y = mon.getSize()
  x1, y1 = mon.getCursorPos()
  mon.setCursorPos((math.floor(x/2) - (math.floor(#text/2))+1), y1)
  mon.write(text)
  mon.setCursorPos( x1, y1 + 1 )
end
Dog #4
Posted 22 September 2015 - 08:15 PM
To center text you would set your x cursor position at half the monitor width minus half the text length. Building on TYKUHN2's example…

local mX, mY = monitor.getSize() --# get monitor width and height
local welcomeText = "Welcome To" --# define the text to be centered
monitor.setCursorPos(math.floor(monX/2) - math.floor(#welcomeText/2), 2) --# center the cursor horizontally
monitor.write(welcomeText) --# write the text to the monitor

EDIT: :ph34r:/> 'd
Edited on 22 September 2015 - 06:18 PM