Edit: Just found out that Blizzard's slice_text is for RGSS3. Shame on me. Editing the question so I don't need another thread.
I'm trying to add a newline on my script. Using \n, however, returns me a weird character.
The string that I'll use will be based on an array index, so I can't (more like don't wanna) do a two-dimensional array and do something like this (unless it's the only case):
for i in 0...text_array.size
self.contents.draw_text(0,32*i,self.width-32,32,text_array[i])
end
Is there any other way to put a line break? Putting characters on the string isn't a problem.
(Old post, just in case)
I'm having some trouble using Blizzard's slice_text to do some line breaks. When I try to draw the sliced text, I get the 'Cannot convert array into string' error. Here a part of my code:
desc = self.contents.slice_text("Lorem Ipsum dolor sit \n amet", 186)
self.contents.draw_text(0, 184, 186, 32, "No. 1: " + desc, 1)
And here is the slice_text code. I'm using a version from KK20, so that it takes \n but I've tried the original one and it didn't worked too.
class Bitmap
# Blizzard's slice_text method. This method can be removed if you have another
# script that already uses it.
def slice_text(text, width)
lines = text.split("\n")
result = []
lines.each{|text_chunk|
words = text_chunk.split(' ')
current_text = words.shift
if words.empty?
result.push((current_text == nil ? "" : current_text))
next
end
words.each_index {|i|
if self.text_size("#{current_text} #{words[i]}").width > width
result.push(current_text)
current_text = words[i]
else
current_text = "#{current_text} #{words[i]}"
end
result.push(current_text) if i >= words.size - 1
}
}
return result
end
end
I don't get the error if I change the code to this:
desc = self.contents.slice_text("Lorem Ipsum dolor sit \n amet", 186)
self.contents.draw_text(0, 184, 186, 32, "No. 1: #{desc}", 1)
But this way the linebreak doesn't works.
The only reason I'm using Blizzard's slice_text is for this script, so if there is any other way to break lines I'd be glad to know. Thanks in advance for the help.
Edit: Just found out that Blizzard's slice_text is for RGSS3. Shame on me. Editing the question so I don't need another thread.
I'm trying to add a newline on my script. Using \n, however, returns me a weird character.
The string that I'll use will be based on an array index, so I can't (more like don't wanna) do a two-dimensional array and do something like this (unless it's the only case):
Is there any other way to put a line break? Putting characters on the string isn't a problem.
(Old post, just in case)
I'm having some trouble using Blizzard's slice_text to do some line breaks. When I try to draw the sliced text, I get the 'Cannot convert array into string' error. Here a part of my code:
And here is the slice_text code. I'm using a version from KK20, so that it takes \n but I've tried the original one and it didn't worked too.
I don't get the error if I change the code to this:
But this way the linebreak doesn't works.
The only reason I'm using Blizzard's slice_text is for this script, so if there is any other way to break lines I'd be glad to know. Thanks in advance for the help.
Share this post
Link to post
Share on other sites