Display text with carriage returns

themusicalduck's icon

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.

MIB's icon

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...

themusicalduck's icon

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.

Luke Hall's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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

themusicalduck's icon

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?

themusicalduck's icon

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.

Morgan's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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:

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

Luke Hall's icon

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