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

need help with a string left to right

Started by jaytime104, 07 September 2012 - 01:29 AM
jaytime104 #1
Posted 07 September 2012 - 03:29 AM
can u help me figur out why this wont work please?
i want it to scroll across the computer when my program starts i found this on another dudes post and it works for his program but i cant seem to get mines as clear as his mines messes up on the last letter mostly.


[attachment=438:the string.rtf]
jaytime104 #2
Posted 07 September 2012 - 03:46 AM
its gots lots of views but no ansers if its not clear what im looking for tell me and ill try to restate it all agin but i realy wanna get this working
Cloudy #3
Posted 07 September 2012 - 08:04 AM
You should put your code in pastebin, not in a downloadable rtf file.
KaoS #4
Posted 07 September 2012 - 11:30 AM
made a pastebin: http://pastebin.com/y9WYYuPq
Mmmmmmmm #5
Posted 07 September 2012 - 11:43 AM
Mostly, that's just a really terrible way of doing it. Just define a single 2d array and scroll through it one column at a time. :/
jaytime104 #6
Posted 08 September 2012 - 12:55 AM
Mostly, that's just a really terrible way of doing it. Just define a single 2d array and scroll through it one column at a time. :/


How would I go about doing tht?
jaytime104 #7
Posted 08 September 2012 - 04:21 AM
could someone tell me what to do to make this work please are give me a link to something tht can cuse im realy lost.
sapient.fool #8
Posted 14 September 2012 - 12:41 AM
Ok, try this code, I think it might do what you are looking for.
Also, I am assuming you meant text coming in from the right side of the screen and scrolling to the left.
If that is an incorrect assumption, you'll need to tweak some of the math to scroll appropriately.



strLine1 = ".d8888. d888888b db	db d88888b d88888b   db   db  .d88b.  db	  d88888b "
strLine2 = "88'  YP `~~88~~' 88	88 88'	 88'	   88   88 .8P  Y8. 88	  88'	 "
strLine3 = "`8bo.	  88	88	88 88ooo   88ooo	 88ooo88 88	88 88	  88ooooo "
strLine4 = "  `Y8b.	88	88	88 88~~~   88~~~	 88~~~88 88	88 88	  88~~~~~ "
strLine5 = "db   8D	88	88b  d88 88	  88		88   88 `8b  d8' 88booo. 88.	 "
strLine6 = "`8888Y'	YP	~Y8888P' YP	  YP		YP   YP  `Y88P'  Y88888P Y88888P "


local marchTextRtoL = function (strMessage,intLine,strHeader,mon,strSep)
	 local intOffset = 1
	 local strHeader = strHeader or "" --Optional
	 local mon = mon or term.native --Optional
	 local strSep = strSep or " | " --Optional
	 local intWidth = mon.getSize()
	 local strBlank = string.rep(" ",intWidth)
	 local _, y = mon.getCursorPos()
	 local intLine = intLine or y -- Optional
	 local strMsgBuilder = tostring(strMessage)
	 local strMsgText = strBlank..strHeader..strSep..strMsgBuilder..strBlank
	 return function ()
		  local intOff = intOffset
		  if intOff > string.len(strMsgText) then
				intOffset = 1
		  end
		  intOffset = intOffset + 1
		  local strMsgDisplay = string.sub(strMsgText, intOff, intOff + intWidth - 1)
		  mon.setCursorPos(1, intLine)
		  mon.clearLine()
		  mon.write(strMsgDisplay)
	 end
end

local scrollLine1 = marchTextRtoL(strLine1,1,"",_,"")
local scrollLine2 = marchTextRtoL(strLine2,2,"",_,"")
local scrollLine3 = marchTextRtoL(strLine3,3,"",_,"")
local scrollLine4 = marchTextRtoL(strLine4,4,"",_,"")
local scrollLine5 = marchTextRtoL(strLine5,5,"",_,"")
local scrollLine6 = marchTextRtoL(strLine6,6,"",_,"")

while true do
	 scrollLine1()
	 scrollLine2()
	 scrollLine3()
	 scrollLine4()
	 scrollLine5()
	 scrollLine6()
	 sleep(0.2)
end



You'll need to tweak a few things to match what you want for your program(duration of scrolling loop, monitor output, etc..)