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

Monitor not getting correct size on first load

Started by Hepcat2299, 29 March 2013 - 11:14 AM
Hepcat2299 #1
Posted 29 March 2013 - 12:14 PM
Hello,
I am currently making a program that will run on a touchscreen monitor and will display some useful information. I use a simple function that centers the text on the monitor. The issue is that whenever I reboot the computer the text (and size of monitor thanks to mon.getSize()) is wrong. my monitor says that it is 29 by 19, but after terminating the program and running it again the monitor and the text go back to the correct 14 by 10.. Not quite sure what the issue is but Ill post the snippets of code that pertian to the monitor printing. Thanks for any and all help!



mon = peripheral.wrap("left")	 --setting up the variable
local w,h = mon.getSize()

function printCentered(str, ypos)
   mon.setCursorPos(w/2 - #str/2, ypos)
   mon.write(str)
end
--useful little function, youre welcome to it if you would like.
print("Width: "..w.." Height: "..h)
--and the basic debug script to show me that it says the wrong size the first time the program runs but fixes itself
JokerRH #2
Posted 29 March 2013 - 01:20 PM
What do you mean?
The size get's changed whenever your program runs?
In that case search if you have a mon.setTextScale line in your program…
Hepcat2299 #3
Posted 29 March 2013 - 01:33 PM
It only returns the wrong monitor size (29x19) the very first time it runs on a freshly rebooted computer. All subsequent times that I terminate and restart the program it works great (monitor size 14x10). It seems the program is having trouble getting the accurate size of the monitor when it first starts up, never had this issue before now so Im not sure if is some kind of bug. Also, I do not set the text scale in the program. Strange eh?
Hepcat2299 #4
Posted 29 March 2013 - 01:37 PM
Well, I derped. I do call mon.setTextScale() at the beginning of my program. Moving it above the line where I set the mon size variable fixes the issue. Thank you.