ComputerCraft, Displaying text to a monitor.

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

Phantomizer

New Member
Jul 29, 2019
25
0
0
This is the script i'm using. What I want to do is output text to a 4 x 1 set of monitors, I want the text centered and scaled in size. However, i'm not sure why this script is not working...no error message, nothing. Any ideas?

Code:
local tText = {
"text"
 
}
local sSide = "back"
local nTextSize = 3 -- change the text size here (from 1 to 5)
 
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)
 

VikeStep

New Member
Jul 29, 2019
1,117
0
0
The place where he is wrapping the peripheral won't affect the problem.
I believe that your problem lies in the fact that you are using a peripheral as an argument.
Try wrapping the peripheral inside the function and only taking text as an argument for printCenter().
If that fails, try adding print(line) inside the for loop to see it actually knows what the line is
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
The place where he is wrapping the peripheral won't affect the problem.
I believe that your problem lies in the fact that you are using a peripheral as an argument.
Try wrapping the peripheral inside the function and only taking text as an argument for printCenter().
If that fails, try adding print(line) inside the for loop to see it actually knows what the line is


I just tested my suggestion to see and you are right. I thought it would work based on some strange behaviour I remember seeing when I first started out with computer craft. I must not have understood the problem well enough. Thanks for clearing it up

deleting my incorrect suggestion

Edit: I did some more testing. It appears that it is actually writing to the monitor but it doesn't like the text scale and monitor size. It worked for me when I left everything the same and used it on a 2*4 monitor, and it worked on a 1*4 monitor when I set the text size to 1
 

angelnc

New Member
Jul 29, 2019
232
0
0
Try printing out the positions where you write the text (on the console).
I think you have an error there, so the computer is actually writing on the monitor, but not on a visible coordinate.