How do a line count based on text wrap/line break?

0 favourites
  • 5 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Starts off with:

    Everything works up to the point. What I need a line count based on the text wrap or line break.

    I have used set globalvariable to tokencount(TextObject.Text,newline)

    Instead of counting the breaks it returns how many lines in the .txt file.

    Result

    Example1 = 2

    Example2 = 2

    Example3 = 2

    The result I am looking for is

    Example1 = 5

    Example2 = 2

    Example3 = 3

    How do a line count based on text wrap/line break?

  • Tokencount(text,newline) counts the number of line breaks, it will not work here.

    I don't think it's possible to correctly count the number of lines in text object. You can use Text.TextHeight property to get the text height in pixels. And then divide this number by an average height of each line, say 30px. You'll get an estimate number of lines which may not be very accurate if you have a lot of text. Also, different browsers render the text slightly differently, so the results may vary.

    With SpriteFont you can calculate line height and the number of lines precisely.

  • Do you by chance have any suggestions for javascript? I tried using this but it didn't work.

    var globalvariable = TextObject.split("\n")

    Note: I just need to count the number of wraps. I have a workaround for text height, width, etc.

  • I tried using this but Construct says: 'return' outside of function. I have the script placed inside a function.

    {var gTextLines = bbcodetext1.split("\n")

    return split.length}

    I have tried it without the brackets.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • split("\n") works the same way as tokencount(text,newline)

    It searches for new line character, which is not there. If you break the text into multiple lines manually (by pressing Enter), then you will be able count the number of lines with those functions.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)