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

Please help me (Display script on monitor)

Started by etalia, 14 February 2014 - 09:22 AM
etalia #1
Posted 14 February 2014 - 10:22 AM
http://pastebin.com/brsE1tjk

I went to use this script on my tekkit map but it did't work on monitor just on the computer screen i don't know why ? i am very noob ! Can you help me please ?
Bomb Bloke #2
Posted 14 February 2014 - 11:14 AM
Line 9, you likely wanted:

screen.write(lettre)
etalia #3
Posted 14 February 2014 - 01:18 PM
Thanks it work but i have a another prob when my message was displayed on monitor the last letters was doubled. This work perfectly on computer! Why not on the monitor ?
Sorry i dont speak very well English
Bomb Bloke #4
Posted 14 February 2014 - 06:04 PM
Looking at the printString function, we have:

function printString(stringV)
	stringV = tostring(stringV)
	lenght = string.len(stringV)
	for i = 20,-lenght,-1 do
		screen.setCursorPos(i, 1)
		for j = 0,lenght do
			printCar(i + j, 1, string.sub(stringV, j + 1, j + 1))
		end
		sleep(0.4)
		shell.run("clear")
	end
end

Say the string has eight characters in it (so "lenght" is eight) - the first "for" loop (using "i") will count from 20 to -8 (repeating 28 times total). With each iteration, the string gets printed one character more to the left.

To print the string, you run the second "for" loop (using "j"), which counts from 0 to 8 (repeating 9 times). First it'll print the eight characters in stringV, then it'll try to print a ninth character - but there's no ninth character in the string, so it writes "" instead. Whatever character was there already gets left there - you really want to write a space over it.

You could re-write the function as:

function printString(stringV)
	stringV = tostring(stringV)
	for i = 20,-string.len(stringV),-1 do
		screen.setCursorPos(i, 1)
		screen.write(stringV.." ")  -- This writes everything in stringV, then concatenates ("adds") a space.
		sleep(0.4)
		screen.clear()
	end
end

Edit: To be clear, "write()" uses word-wrap. "term.write()" does not, so you don't need to check each character to see if it'll fit on the screen or not. Your monitor's "write()" function ("screen.write()" here) is much the same as "term.write()".
Edited on 14 February 2014 - 05:08 PM