Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
Bigace360

[Help] Line Break question? [Solved]

Recommended Posts

Okay so in my new script Option menu I have some text in my module that needs to be on two lines.

"Change the volume used for background music. \n" +
"Hold SHIFT to change increment by 10."

 

as you can see I use the line break command "\n" however when I start the game up I get this instead.

 

helpmenu.png

 

How do I get it to appear on two lines instead of one.

Edited by bigace

Share this post


Link to post
Share on other sites

That doesn't work in RM, or really any graphics library that I know of. Line break and carriage returns are for writing to files, and are not parsed by the graphics context. It is simply creating a graphic based on the string and drawing it to the screen at the coordinates you specify.

 

Your trying to mix operations of two unrelated things.

Share this post


Link to post
Share on other sites

@ForeverZer0 but it works in rmvxa, so something must be written differently in that engine. So what should I apply to Option System Engine that would give me that effect.

Edited by bigace

Share this post


Link to post
Share on other sites

They may have made the method for convenience, but this is not how things would, or even should work.

If I specify I want text drawn, and I want it to use this region of space to do it, I would not want it "automatically" start exceeding that. That is an added feature for amature game makers, that actually restricts control.

 

If you want to create a similar method, just split the text into an array, using the '\n' character to determine where to split.

 

text = "my string with line breaks\nis going to use\nthree lines."
text.split("\n").each_with_index {|str, i|
 self.contents.draw_text(0, i*32, self.contents.width, 32, str)
}

Share this post


Link to post
Share on other sites

So I guess I have to rewrite the help window because when I tryed to apply it:

def update_help
 @help_window.set_text(
  if item.nil?
   ''
  else
   text = COMMAND_VOCAB[item][3]
   text.split("\n").each_with_index do
 |str, i|  self.contents.draw_text(0, i*32, self.contents.width, 32, str)
   end
  end
 )
end

 

I got an error that pointed towards the line 26 in the Window_Help. saying it cannot convert Array into string.

Share this post


Link to post
Share on other sites

Your method is poorly structured.

 

You are placing it within the set_text method, and it is returning an array, which is getting passed to the that. If you want to use it with help windows, alias set_text within the Window_Help class, not try to do some messy stuff within the method call, since the return values are not the same.

 

To simplify why you are getting the error, the code you posted is exactly the same as this:

(lets say "item" is the string from my example...

 

if item.nil?
 @help_window.set_text('')
else
 @help_window.set_text(['my string with line breaks', 'is going to use', 'three lines'])
end

Share this post


Link to post
Share on other sites

Ya just figured that out like 10 minutes ago. tongue.png And return the update_help method back to its original state, heres the Window_Help code.

 

class Window_Option_Help < Window_Help
def set_text(text, align = 0)
 if text != @text || align != @align
  self.contents.clear
  self.contents.font.color = normal_color
  text.split("\n").each_with_index do
   |str, i| contents.draw_text(0, i*line_height, self.width-32, 32, str)
  end
  @text, @align, @actor = text, align, nil
 end
 self.visible = true
end
end

 

The problem now I'm getting is that it doesn't show the second line of text.

 

oh ya

line_height = 32, I already had it in the Window_Base if you were wondering.

Share this post


Link to post
Share on other sites

Because you are not recreating the contents to be of the appropriate size, but merely clearing it. The Bitmap you are attempting to draw to is only 32 pixels high, so anything above that does not get drawn. Something like this should work, but you I hope your window is sized correctly, or you wall have to resize it as well, and that's where the messiness and control restriction come in.

 

class Window_Option_Help < Window_Help

 alias multiline_set_text set_text
 def set_text(text, align = 0)
   if text != nil
  lines = text.split("\n")
  if lines.size <= 1
    multiline_set_text(text, align)
  else
    self.contents.dispose
    self.contents = Bitmap.new(self.width - 32, lines.size * 32)
    lines.each_index {|i|
	  self.contents.draw_text(0, i*32, self.contents.width, 32, lines[i]) }
    @text, @align, @actor = text, align, nil
  end
   self.visible = true
 end
end

Share this post


Link to post
Share on other sites

Okay sweet thank you it works, however selecting over anything that has more then two lines apparently lags the game a bit as the background starts to move slower, but moves normal speed when I highlight over text that only has one line.

 

Edit: Appearently my Warrior Engine was causing the lag as I removed it and the game didn't have a lag.

Edit2: It's probably the bitmap class in my Warrior Engine as when ever there is a probably with draw_text method it send me there.

Edited by bigace

Share this post


Link to post
Share on other sites

It actually might be that method. I didn't add a check to ignore if the @text == text. Since set_text is usually called in update methods, it may be redrawing every frame, which would cause lag. Just alter the "else" to "elsif @text != text" and see if ti helps.

 

EDIT:

Actually, it might be better to rearrange the whole method a bit to eliminate the need for calling "split" every frame. Maybe check that @text != text before doing anything else.

Share this post


Link to post
Share on other sites

The "elsif @text != text" works fine actually as there is no lag, thank you again for your help, now I can upgrade the script.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...