Newline not working?

0 favourites
  • 6 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hi, I would like to count the number of lines in a textbox.

    I thought "tokencount(Mytext.text, newline)" would do the trick, but apparently not.

    Does anyone have an idea how to count the number of lines in a textbox?

    Thanks for any help anyone can offer.

  • Works for me.

    Can you post a screenshot or capx?

  • Hey Asmodean, thanks for the reply and for checking! I really appreciate it!

    I am wondering if this is a beta problem? (Using Beta 265) Or am I doing something wrong here? Capx included:

    https://drive.google.com/file/d/1oWzceQBNv7kUY_C292ZtkLuKSbQaRx-j/view?usp=sharing

  • It doesn't work because that are word wraps (soft breaks), not newlines (hardbreaks). Word wraps are not in a string that is a formatting feature of the software

    which shows the string.

    There is a workaround. Try

    floor(Text.TextHeight/(Text.FaceSize+round(Text.FaceSize/3)))

    TextHeight: the real height of the text in the textbox (in pixel).

    FaceSize: Font size (in pixel).

    Problem is, you have free space between the text lines, my guess was 1/3 of the font size. but this could vary (size , font itself). No clue if this always correct.

  • It doesn't work because that are word wraps (soft breaks), not newlines (hardbreaks). Word wraps are not in a string that is a formatting feature of the software

    which shows the string.

    There is a workaround. Try

    floor(Text.TextHeight/(Text.FaceSize+round(Text.FaceSize/3)))

    TextHeight: the real height of the text in the textbox (in pixel).

    FaceSize: Font size (in pixel).

    Problem is, you have free space between the text lines, my guess was 1/3 of the font size. but this could vary (size , font itself). No clue if this always correct.

    Asmodean You sir! Are a life-saver! This is perfect for the few lines I will be using!

    Thank you so much for this help :) I am not a coder really, and just muddling through. So there is no way at this stage of my ability, would I had figured that out by myself! Very kind of you to take the time :) I owe you one my friend!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Actually, this is perfect. A little tweaking of the line height and I got it working great for an entire page of text if needed. All depends of the font size / line height. You have no idea how helpful this is! My hero! :)

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