- Joined
- Aug 28, 2013
- Messages
- 349
- Reaction score
- 100
- First Language
- German
- Primarily Uses
- N/A
Hi, I wanted to write a function, which gets a text and will automaticly put an \n in the text if the text is bigger than the screen.
Here is the code:
def draw_text_with_n(text, x, y) t = text.split(" ") n_text = "" t.each do |word| line = "" if line.length + word.length < self.width line << "#{word} " else n_text = line + "\n" line.clear end end draw_text_ex(x, y, n_text) endNow i have the Problem that this line:
line << "#{word} "Makes this:
"This "
"is "
"an "
"example"
But it should look like this: "This is an example"
So my code dont work.
Could someone help me pls?
Here is the code:
def draw_text_with_n(text, x, y) t = text.split(" ") n_text = "" t.each do |word| line = "" if line.length + word.length < self.width line << "#{word} " else n_text = line + "\n" line.clear end end draw_text_ex(x, y, n_text) endNow i have the Problem that this line:
line << "#{word} "Makes this:
"This "
"is "
"an "
"example"
But it should look like this: "This is an example"
So my code dont work.
Could someone help me pls?
Last edited by a moderator:
