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.

Few Questions about Text Formatting with RGSS/RGSS2

Hey everyone,

     I hope this can serve as an introduction as well as my first question to contribute to the RMXP Community.

     I am having a problem finding the correct Function and maybe even the correct Syntax to achieve my goal.  I am not new to programming or RUBY, but I often get it mixed it with the syntax and functions of other Programming Languages that I know, so this problem is rather embarrassing to admit to lol.  :blush:

     Question #1, can someone ascertain as to why I am unable to insert escape characters within the sprintf function as I would be able to with the print function in most other OOPLs?  I am trying to create the following effects with the following code.

          string variable = "Hello"
          another_string_variable = "World!"
          text = sprintf("%s\n %s", string_variable, another_string_variable)

          ----->Hello
                   World!
     However, I am given,
     
          ----->Hello? World!

     with the "?" being placed within a box.  Common Sense dictates that the function does understand that I am trying to use an excape character, but it seems as if it doesn't know what to do.  Referencing the Ruby Manual, using escape characters is definately possible.

     Ultimately, I am using self.contents.draw_text to draw some text within a window.  However, since the text is of vast quantity, it must be expressed with multiple lines, and in the practice of good programming, I would like to not have a self.contents.draw_text for every line.


     Question #2, can someone give me the syntax to open and read from a text file located in the directory with the rest of the RV Data file?  I also can't remember if its possible and/or necessary to define a parameter which will represent the amount of lines to read, as well as which line to start on.  Again, this will be used to display vast amounts of text.

Thanks for your help everyone,

Osgiliath
 

poccil

Sponsor

Unfortunately, the draw_text method of the Bitmap class does not break lines.  The syntax is correct, but the method does not handle line breaks as expected.  You must resort to multiple calls of draw_text.

Here is an example of reading from a text file (in this case, textfile.txt) line by line:
Code:
File.open("textfile.txt","rb"){|f|
  f.each_line {|line|
   print line
  }
}
 

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