Display text with carriage returns

Dec 6, 2010 at 8:24pm

Display text with carriage returns

I have some text stored in a .txt file. I can load it into a text object and when I double click on it, the text box appears and the text looks right.

I’d really like to be able to display the same text in either a comment box or a textedit box, but it seems like it’s impossible to display carriage returns. I’ve tried including \cr and cr in the text but it doesn’t make a difference. Ideally I want to be able to send the message dump to the textobject and have it display the saved text file correctly somewhere on the patch. I realise dump outputs the text line by line, so all I’m getting so far is the final line being displayed.

#53770
Dec 6, 2010 at 8:35pm

not sure, but couldn’t you use [zl group] to put the text back together? this would of course mean that the text will be backwards (first line will be last line), but there should be ways around that too…

#193416
Dec 6, 2010 at 10:48pm

I tried using zl group, but couldn’t really get it to do what I wanted. It seems like to use it properly, you need to actually know how many words are in the file, which isn’t useful in this case.

I can actually output all the lines and have them written together by using append when passing it to the textedit object. But the lines are just put one after the other, and the carriage returns are ignored.

I thought I would try setting Separator in the inspecter on the textedit object to cr and adding cr to the end of each line with an append object. Then I could bang the textedit object and output the text to another textedit object with the carriage returns in tact. But what it seems to do is just output the lines one after the other again and put it back exactly to how it was when it is dumped from the text object in the first place.

#193417
Dec 7, 2010 at 2:01am

Sending the number 10 to [itoa] will output a newline character, here’s an example:

– Pasted Max Patch, click to expand. –
#193418
Dec 7, 2010 at 10:28am

Thanks Luke, that works perfectly now.

I have just one more question though. Is it possible to scroll through text when it is too big for the textedit box? With a scrollbar or just with the mouse wheel?

#193419
Dec 7, 2010 at 11:31am

Never mind I figured it out. In the end I’ve decided to use a jweb object with html files so I can format them more easily and have a scrollbar included.

Thanks for the help.

#193420
Feb 5, 2011 at 4:24am

Thanks for the suggestion to use jweb! I was looking for a solution for making a maxhelp patch that could display a README and thankfully the jweb “readfile” command honors relative paths, unlike the “read” command for other objects such as [text]. Astonishingly simple, here it is:

– Pasted Max Patch, click to expand. –

This patch will read the README file in whatever directory it is located.

#193421
Feb 5, 2011 at 1:14pm

As long as the file is in the max search path. I haven’t checked how it deals with files in different directories with the same name.

lh

#193422

You must be logged in to reply to this topic.