add line break in text object while importing a txt file

Hello,

I got a little problem with adding a line break (
) to an text object that shows loaded text from a text file.
I know i can use
in a string, or directly in the text object to insert a new line, but that does not work while reading text from a file. It just shows the
instead of breaking the text into a new line.

Can anyone tell me how i insert a line break?
Or do i need to use split() and replace() in order to input a line break?

edit

more info in post 3

Thanks alot.

Have you tried loading in the lines one-by-one and then merging them with newlines between them?


# Warning, untested semi-pseudo code

# Assumes 'lines' is a list of the lines loaded from file.
finalText = lines[0]
for i in range(1, len(lines)):
  finalText += '
' + lines[i]


It really depends on how long your text file is. Doing string operations like that can be very expensive.

Have you tried loading in the lines one-by-one and then merging them with newlines between them?

I see that i miss more info in my first topic, (sorry was a bit tired this morning).

I have 1 text file, that acts like a book.
Every line in that text file represent a page, while the first line of the text file is the title of that “book”
(it wont be a real book, it will be an info panel for in game)

I get the data by lines[0] and lines[1] and upwards.
To get to the next line / “page” i simply add +1 to the lines[1] so u get line[2], line[3], etc.

The problem i have is breaking (for example) line[1] into new lines with
.

I had the same idea at first place, but that wont work with separated lines.
so i am thinking that i need to use replace and split to make a few line breaks in it, and then make a new string out of it again. But like you said it looks to heavy to break down every line and then paste them all back together again.

Thats why i am wondering why
works in a string, but if you load it from a file it does not work, but it just gets displayed as text.

Because it is not interpreted as control character. It simply is the two character string ‘’+‘n’.

Why do you have each page in one line? This sounds a little bit silly.

You can mark a page break with a keyword. e.g. ‘<page break>’.
This way you can use normal text editing.

In that case you will have to manually convert those "
" strings into control characters with a replacement operation on the string.

Why do you have each page in one line? This sounds a little bit silly.

to create some sort of info panel / quest system. This way i have one text file for a quest, and that quest can be set as more pages or stages in that particular quest line. And now that it is in one line the text only gets broken by the text wrapper, while i want some empty lines in between to make the looks a bit better.

example:


I have used the for loop on the split() data and it works how i want now by using <br> as a tag to split at.
Thanks all.

You did not wrote about a text wrapper. Nevertheless you can use a text wrapper in conjunction with the lines similar as word does. So you get long paragraphs separated by end-of-line and pages separated by keywords. This is input.

A page parser extracts the lines for the page you want to display without the keyword.
The text wrapper inserts additional end of lines to this extracted text.

This way you get the output that can be displayed on screen.

Alternative you can use keywords to separate paragraphs and end-of-line for page break (as you suggested). The method is exactly the same. end-of-line is a key word too ;).

Which method to use depends on what is easier to deal with (as author of the text). In long pages you usually have more paragraphs than page breaks (that is why I wrote it sounds silly to avoid end-of-line as separator).
In your dialog pages it might be you have more pages than paragraphs.

You did not wrote about a text wrapper

Yest thats true, this becouse the wrapper is not permanent, i tried alot and well i am still leaning python, by trying to build things what i can use. in first case i readed that the wrapper could do nice stuff to text, but it seems that even the wrapper blocks the line breaks.

So i did not know what to do to handle that. i removed it and decided to manually break the lines.

Which method to use depends on what is easier to deal with (as author of the text). In long pages you usually have more paragraphs than page breaks (that is why I wrote it sounds silly to avoid end-of-line as separator).
In your dialog pages it might be you have more pages than paragraphs.

Ok so actually it does not make a difrence how to do it? becouse that was another thing where i was worried about, if i did it the right way :). and yes the dialof system wont have so much paragraphs, its just a chuck of text to show you the objective.

I thank all of you for the verry helpfull info.

PS, i actually got a little problem that popped up, hopefully someone can answer this one aswell.
it seems that when i and an overlay to my scene my mouse script acts a bit strange, the rotation starts to drift (u give the mouse a little push and it keeps rotating until i hit a key or keep the mouse still at a position. Verry strange, does someone now the solution for this aswell? thanks alot.

it happend with all the mouselooks i tried :S blender 2.68

Thanks again

This sounds like a rounding problem.

This happens when the screen size is not on even (e.g. 177). When the code sets the mouse cursor to the middle of the screen it truncates the decimal places which create a small but constant movement.

I suggest to open a new thread to deal with this issue.

I suggest to open a new thread to deal with this issue.

Ok, but this is not needed for me anymore, as kheetor mentioned there are some issues with some things in version 2.68.
I always ignored the drifting becouse it worked fine in lower versions of blender (but still its kinda irritating).

While looking at the thread kheetor mentioned, i downloaded the 2.69 test build and it works how it should be again.

Going to mark this as solved, once again thanks all!