I have a text box in my game that says stuff with the text option in face select mode, and it works, but how do you make a multiple-line text box, instead of just a single line text box?
You can’t, really, you just have to use multiple text objects.
Pooba
Pooba is right. The text that shows up in your text box has been stored in a string (which you enter in the property box. You can normally produce a new line inside a string by using "
" but this option doesn’t seem to work. It would be handy if it did.
Once we get the game engine back, it would be nice to implement that into gameBlender’s code…
…
Here is what you do. Make 4 text planes. Here is a python script what will fit a sentence into those 4 lines.
cont = GameLogic.getCurrentController()
#Text Objects, not that each one is connected to the controller
Line1 = cont.getOwner("Line1")
Line2 = cont.getOwner("Line2")
Line3 = cont.getOwner("Line3")
Line4 = cont.getOwner("Line4")
def Multiline(Text, Max_Words):
#divide text into words
words = Text.split(" ")
#create lines
lines = [[], [], [], [] ]
i = 0
j = 0
for word in words:
if j != Max_words:
lines[i] += word
j = j + 1
else:
i = i + 1
j = 0
return lines
a = Multline("blah, blah, blah, blah, blah, blah, blah, blah", 2 )
Line1 = a[0]
Line2 = a[1]
Line3 = a[2]
Line4 = a[3]
I have never actually done this and i bet the code is full of errors, but it will give you an idea on how it is suppose to work.
Nice!
Let me see if I understood, you count the number of words to make different text lines? why? isn’t it better to count the number or chars instead? or if I got it all upside down… ok… sorry … i’m learing…
Yeah, counting characters would work a lot better, unless that’s what your doing
The best would be to count characters, and split on words:)
i = 0
j = 0
for word in words:
if j+len(word)<= Max_chars:
lines[i] += word + " " #Need the extra space, cause the split removed it
j += len(word)+1
else:
i += 1
j = 0
I think there is also a python module somewhere that does something like this but it has a few more options to it in how to put things on further lines. You can also allow newline capability by presplitting the string with the "
" character and processing each line of that. And you can scroll if you add in an offset amount (which you save as an object prop) and then make a control to add to the offset amount. So you could take a string, convert it to a list of who knows how many lines, then copy the 4 lines to the 4 .Text props starting at an index equal to the offset.
i did not want to split it with chars because words can get screwed up. You can have half a word on one line and the other half on the other line, to make sure this doesnt happen i decided to count words. But using words has cons too, for exaple if you have very long words lines will over flow.
THat’s why you use both If a word makes it go past your char limit, put it down on the next line. If it still goes over the char limit on the next line, split the word up (but words shouldnt be THAT long.)
But one thing both these methods miss is that different letters take differing amounts of space. The best method would calculate how long a line would really be, taking into account how freaking Wide w’s are etc. But while it’s the “best” method, it’s probably overkill:)
Yeah saluk, I was thinking the same thing! Maybe it can be a good python excercise for me to create a script that behaves like that (and yes yes you are a super blender python genius… but I still wanna learn)
I really have no comprehension of python whatsoever.
yo saluk… you wouldn’t by any chance lend us yer funky text script, right?..
Just kidding…
Lol, I haven’t written one:)
Well, actually I wrote one for my multiplayer game a year ago (for chatting ) but I dont have it anymore. It used number of characters, and went to the next line based on if the next word goes over the limit. It didn’t have a solution for rediculouslylongfreakyweirdwordssuchasthis.
Hehe.