Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: monkey0506 on Sun 25/06/2006 03:55:33

Title: MODULE: LineBreak v1.0a
Post by: monkey0506 on Sun 25/06/2006 03:55:33
 (http://www.meleepta.com/ags/LineBreak_Manual.txt)
Quote from: The LineBreak v1.0 Manual[/url]/*****************************
Description:

The LineBreak module was written with the intent to provide functions to insert,
remove, and manage line-breaks within  Strings  of  text.  The  module  contains
functions for adding line-breaks (a String which is interpreted by the  module),
testing whether a String contains any line-breaks, converting module  line-break
Strings into AGS compliant line-breaks (an  opening  bracket  ('[')  within  the
text), converting AGS bracketed line-breaks into  module  line-breaks,  counting
the lines a String contains, retrieving the type of line-break a String contains
(hyphenated, broken based on width, or based on a set of  delimiters),  removing
line-breaks from a String, parsing a String which is then read back  by  another
function a single line at  a  time,  and  retrieving  the  last  parsed  String.
*****************************/

******************
The LineBreak Module
******************

A module for creating and managing line-breaking text.

Now verified (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=27104.0) to work better and be more stable than AGS itself!*
******************

That's right people. I actually finished a module this time. I tested it rather rigorously to make sure everything works the way I intend it to (this means if you encounter any errors they were intentional and not bugs :=).

There is a related discussion here (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=26974.0) (which should now be closed ;)), but please post further comments/questions here.

Download the LineBreak module v. 1.0a (http://www.meleepta.com/file.php?dir=ags&file=LineBreak_1_0a.rar)
Read the LineBreak module manual (http://www.meleepta.com/ags/LineBreak_Manual.txt)

[NOTES:]

Title: Re: MODULE: LineBreak v. 1.0
Post by: fovmester on Sun 25/06/2006 10:15:04
So if I understood correctly one can do linebreaks in AGS by inserting the [ sign?

Ex:

I am two lines [of text!

would read:

I am two lines
of text!


Correct?
Title: Re: MODULE: LineBreak v. 1.0
Post by: monkey0506 on Sun 25/06/2006 15:37:20
Well...yes.

The reason I made the module is because I need to be able to extract the lines so that I can display one line at a time.

[EDIT:]

I've uploaded v. 1.0a of the module with a minor bug fix. I say minor because it was something incredibly stupid on my part.

Inside of the LineBreak.AddLineBreaks function there is a line which reads:

      while (GetTextWidth(Temp, font) < width)
        Temp = Temp.AppendChar(Text.Chars[Temp.Length]);


Where Temp is a copy of Text (a String parameter) used to store the next line to be added to the String to be returned (which is pieced together a single line at a time).

To hold the character index in Text without having to worry about the line-break Strings being inserted into the copy of the text I have an integer called index.

The problem here is that if this loop is creating the second line it could access the wrong index in Text because as shown above I have just accessed the index equal to that of the length of the String Temp (I say "could" because in test cases with text only containing two lines I didn't incur this error).

The fix was simple once I narrowed it down (from the other 50 lines inside the function):

      while (GetTextWidth(Temp, font) < width)
        Temp = Temp.AppendChar(Text.Chars[index + Temp.Length]);
Title: Re: MODULE: LineBreak v. 1.0a
Post by: jasonjkay on Mon 26/06/2006 12:39:11
Sounds good, i'll add it to my site.
Title: Re: MODULE: LineBreak v. 1.0a
Post by: monkey0506 on Tue 27/06/2006 04:05:56
Just as an example of how this could be used:

String Sentence = "This demo game is going to demonstrate how the LineBreak module can be used to manage line-breaking text. We'll start with the Labels below.";
Sentence = LineBreak.AddLineBreaks(Sentence, eLineBreak_Word, 200, 2);
LineBreak.Parse(Sentence);
String Line = LineBreak.GetLine();
while (Line != null) {
  player.Say(Line);
  Line = LineBreak.GetLine();
  }


This code would automagically divide the text (by words) into pieces of no more than 200 pixels (in font 2) before displaying (the player character saying) it.

This is an example of the text used in the demo game, which is currently on hold until the bug mentioned in the first post is fixed (so if you really need more examples of how to use this or what it does, bug Chris (http://www.adventuregamestudio.co.uk/yabb/index.php?action=pm;sa=send;u=1) wait a little longer...Chris is very busy. :=)
Title: Re: MODULE: LineBreak v. 1.0a
Post by: HeirOfNorton on Thu 06/07/2006 16:13:58
Ahem...

Quote from: Pumaman on Sat 14/01/2006 22:47:30
* Fixed String.Contains not working properly with strings >200 characters.

So it should work right in the newest version.  :)
Title: Re: MODULE: LineBreak v. 1.0a
Post by: monkey0506 on Fri 07/07/2006 05:06:21
Thanks HoN (for the notice; Pumaman for the fix :=).

With that fixed, I should be able to get the demo made up this weekend YAY!