Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Paragraph formatter - something went awry

Hi again. I've been trying to use the following:
self.contents.draw_text(0, 0, 320, 32, @tip_message[rand(@tip_message.size)])

And everything works fine except that if a line is too long the message gets cut off. I've browsed the net for a remedy and found two scripts:

> ATP(Advanced Text Paragrapher) at http://gamebyyou.pl/viewtopic.php?t=28 . The problem is that whenever I activate a script that is to draw text the game shows:

???? 'Paragraph_script' 86? Type Error ??
cannot convert Fixnum into string


And

> http://rmrk.net/index.php/topic,22215.0.html , but this time the message says:

????? 'Window_TIP' ? 195 ??? NoMethodError ???????? undefined method 1 bitmap' for #<Bitmap:0x711eb50>

Which in my code is:

195 self.contents.bitmap.draw_paragraph (0, 0, 300, 32, @tip_message[rand(@tip_message.size)])

The second script would suit me better so I'd like to focus on that one. I can provide you with all info and screens you need, but my project has been on hold for a week now and I'd really use your help :|
 
Code:
class Bitmap

  #-------------------------------------------------------------------------

  #   Name      : Draw Paragraph

  #   Info      : Draws a Paragraph

  #   Author    : SephirothSpawn

  #   Call Info : Five

  #               Integer X and Y, Define Position

  #               Integer Width, defines the width of the text rectangle

  #               String Text, Information to Draw

  #               Integer Indent Amount of Space to indent by

  #               Integer Line_Height line height

  #-------------------------------------------------------------------------

  def draw_paragraph(x, y, width, text, indent = 32, line_height = 24)

    ox, oy = indent, 0

    for word in text.split

      ow = text_size(word).width

      if ow + ox > width

        ox = 0

        oy += line_height

      end

      ow = [ow, width].min

      draw_text(x + ox, y + oy, ow, line_height, word)

      ox += ow + text_size(' ').width

    end

  end

end

Insert that into your script somewhere.

Works very similar to draw_text. Just draw_paragraph(x, y, width, text, indent, line_height)

x, y - Top left position of text lines
width - width of your paragraphc
text - Long text string
indent - pixel indention of first paragraph
line_height - height of text (you want the font size + 2 ideally)
 
Code:
class TIPWindow < Window_Base

 

 def initialize

   super(150, 100, 350, 250)

 self.contents = Bitmap.new(width-32, height-32)

 

 

    @tip_message = ["Mana regenerates out of combat at the rate of one point per 20 sec",

"In order to get bonus attributes you need to equip all three kinds of gear",

"If you need better traveling gear try visiting your guild. They can offer you a handful of advice"]

# I have deleted the unnecessary Tips, which would do nothing but clutter the script

 

self.contents.draw_paragraph (160, 110, 330, 24, @tip_message[rand(@tip_message.size)])

    end

 

end

 

 

 class Bitmap

  #-------------------------------------------------------------------------

  #   Name      : Draw Paragraph

  #   Info      : Draws a Paragraph

  #   Author    : SephirothSpawn

  #   Call Info : Five

  #               Integer X and Y, Define Position

  #               Integer Width, defines the width of the text rectangle

  #               String Text, Information to Draw

  #               Integer Indent Amount of Space to indent by

  #               Integer Line_Height line height

  #-------------------------------------------------------------------------

  def draw_paragraph(x, y, width, text, indent = 32, line_height = 24)

    ox, oy = indent, 0

    for word in text.split

      ow = text_size(word).width

      if ow + ox > width

        ox = 0

        oy += line_height

      end

      ow = [ow, width].min

      draw_text(x + ox, y + oy, ow, line_height, word)

      ox += ow + text_size(' ').width

    end

  end

end

Thank you, SephirothSpawn. I'm just begining to comprehend RGSS and as so I have spent half an hour to adjust the thing :| I'm affraid that because of my recklessness I cut out too much and was left with a blend of SepirothSpawn's, Modern_Algebra's and my scripts. Sorry for asking, but after many trials and errors it seems I cannot find the answer on my own. Could anyone revise the above code (it's a short one, deleted most of @tip_message) in terms of order and unnecessary/lacking phrases? The message I've been getting now is:

Line 33 No method Error
private method 'split' called for 24:fixnum

which refers to SephS's script (that's the point when I decided not to mess with it anymore). I'd be really grateful (and learn quite a bit)
 
Thanks, now the script doesn't display any error messages. Unfortunately I don't see any text either :| I tried to resize the window, but to no avail ;| Anyone knows why the text is not displayed (or is invisible..?)
 
Back to the draw_paragraph line... There you set high values for x and y and that doesn't let you see the tips on screen.

self.contents.draw_paragraph(160, 110, 330, @tip_message[rand(@tip_message.size)], 24)

You better change them with 0, 0 or something like that.

BTW, I tested this in VX, but I guess this will work on XP, too.
 
I tried that before and it didn't work. Currently it's on 0,0,100, @tip_message[rand(@tip_message.size)], 24 and doesn't work neither on super (0, 0, 640, 480) nor on (1, 1, 300, 250)

You said you've tried it on VX? Did it work without any problems there?
 
Yeah, that's what I said before... Are you sure you're using the legal version of RM? I ask you this because the illegal version had a problem with displaying fonts (at least in XP)... If it's legal, try to change the font name to one that will always work like 'Arial' (if you're not using it already).
 
It worked! Heck if I know why, but at least this window issue is finally solved. I'll delve into it a little more later (and change the font, Arial is so... crude). Thank you everyone for your patience :) Now I'm gonna play with mah new function :D


One last question: If I wanted to call and abort my Window via the 'Script' command what should I write apart from TIPWindow.new ?

I mean: The whole Scene / Window script is launched when the game is successfuly loaded, and it works perfectly, waiting patiently until I press 'C', but when I use it via 'Script' the window is displayed for 1-5 seconds and then vanishes without any user's input.

I was thinking of ' if Input.trigger?(Input::C) ' and/or ' .dispose ', but each time I try to program it correctly, either in the Script Editor or via 'Script', there's something wrong with the syntax ( it's always the syntax.. @_@ ). Is there an easy method to do it or should I think of an alternative method of presenting the info outside the 'Loading Screen Scene' (I don't want to mess up the working one)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top