MODULE: LineBreak v1.0a

Started by monkey0506, Sun 25/06/2006 03:55:33

Previous topic - Next topic

monkey0506

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 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 (which should now be closed ;)), but please post further comments/questions here.

Download the LineBreak module v. 1.0a
Read the LineBreak module manual

[NOTES:]

  • This module was written with AGS 2.72 RC1 and may or may not be compatible with earlier versions of AGS (verified 01 July 2006 by monkey_05_06 to work with AGS 2.71).
  • This module contains new-style Strings and is NOT compatible with any versions of AGS prior to AGS 2.71.
  • String.Contains is currently bugged, so this module will NOT work with any Strings longer than 200 characters. (Fixed as of AGS 2.72 Final; using Strings longer than 200 characters with this module and prior versions of AGS is unsupported as String.Contains is bugged in prior versions)

    [EDIT:]

    25 June 2006 - Updated to version 1.0a with a minor bug fix which was returning invalid Strings from LineBreak.AddLineBreaks.

    *Just kidding. There's currently a bug with String.Contains which causes the function to return junk values with Strings greater than 200 characters. This function is extensively used by the module, so if you try to pass Strings greater than 200 characters it won't work (yet).

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

    The bug with String.Contains has been fixed.

    15 August 2006 - I'm changing my host, so you may need to right-click and choose "Save as..." (in my experience trying to link directly to the files opens it as if it were a text file). If that doesn't work, feel free to PM me and let me know. I'll try and have this issue resolved as quickly as possible. Thanks.

fovmester

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?

monkey0506

#2
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:

Code: ags
      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):

Code: ags
      while (GetTextWidth(Temp, font) < width)
        Temp = Temp.AppendChar(Text.Chars[index + Temp.Length]);

jasonjkay

Sounds good, i'll add it to my site.
http://www.americangirlscouts.org/agsresources/ - Mods, plugins and templates.

monkey0506

Just as an example of how this could be used:

Code: ags
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 wait a little longer...Chris is very busy. :=)

HeirOfNorton

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.  :)

monkey0506

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!

SMF spam blocked by CleanTalk