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

wrapping text around monitor?

Started by jefrbunn, 08 December 2012 - 06:27 PM
jefrbunn #1
Posted 08 December 2012 - 07:27 PM
hello all I am trying to make a program to function as a message board in game for me and some friends on a server. I wanted to make a program that basically asks for a name and a message and that would be diaplyed on a monitor (3x3 currently).

I am also saving the messages/poster in a log so that I can possibly add redstone buttons to scroll through previous messages.

The issue I have is that I cannot make the text wrap around the edge of the monitor. I tried a few things but they never seemed to work. also could not find any code that wraped things for monitor.

Below is my code:

Spoiler

shell.run('clear')
UserLog ={}
MsgLog ={}
local lognum = 1
---------------
print('computer ID = '..os.getComputerID())
local Screen1 = peripheral.wrap('left')
Screen1.setTextScale(1)
local Sx, Sy = Screen1.getSize()
print('Screen Size = '..Sx..'  '..Sy)
Screen1.clear()
Screen1.setCursorPos(1, 1)
Screen1.write('- Message Board  ------------')
Screen1.setCursorPos(1, 2)
Screen1.write('-----------------------------')
while true do
shell.run('clear')
print('---------------------------------')
print('--- Message Board Application ---')
print('---------------------------------')
print('Press M to leave a message')
   local event, param1 = os.pullEvent ("char")
   if param1 == "m" then -- if the returned value was 'e'
---------Ask for Id and message
  print('Who is leaving the message?')
  local UserID = read()
  print('What is your message?')
  local Message= read()
  table.insert(UserLog, lognum, UserID)
  table.insert(MsgLog, lognum, Message)
   else
	   shell.run('clear')
	   print ("Wrong button!")
	   sleep (1.5)
   end
   if UserLog[lognum] and MsgLog[lognum] ~= nil then
  Screen1.clear()
  Screen1.setCursorPos(1, 1)
  Screen1.write('- Message Board  ------------')
  Screen1.setCursorPos(1, 2)
  Screen1.write('-----------------------------')
  Screen1.setCursorPos(1, 4 )
  Screen1.write('-- Posted by '..UserLog[lognum])
  Screen1.setCursorPos(1, 5 )
  Screen1.write(' '..MsgLog[lognum])

  shell.run('clear')
  print('Message Left!')
  lognum = lognum + 1
  sleep(2)
end


end

Any help would be appreciated!

I eventually want to make this a rednet system with multiple boards!
GopherAtl #2
Posted 08 December 2012 - 07:36 PM
simplest solution: use term.redirect. term.redirect redirects all the normal term methods to whatever wrapper you pass in, in this case a monitor. While redirected, all write() and print() calls will go to that device. Then you can switch back with term.restore().

Example:


local monitor=peripheral.wrap("right")

print("This is on the computer's screen")

term.redirect(monitor)
print("This will be on the monitor!")
term.restore()

print("and back to the screen.")