How do I detect line breaks from CSV data?

0 favourites
  • 7 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Hello!

    I'm trying to detect line breaks in my text objects so I can dynamically alter dialogue box images.

    I looked here and got a great answer using RegexMatchCount on Newlines in the text object:

    How Do I Detect Line Breaks?

    However, I'm using Rex's CSV plugin to load a lot of dialogues from CSV files. I have everything working except that when the dialogue loads and wordwraps into the text object, the wrapping doesn't seem to create any sort of Newline indicator for the Regex to detect.

    Is there a way to count these automatic line breaks from the word wrap when the dialogue is drawn from a CSV file?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm trying to detect line breaks in my text objects so I can dynamically alter dialogue box images.

    ... when the dialogue loads and wordwraps into the text object, the wrapping doesn't seem to create any sort of Newline indicator...

    Is there a way to count these automatic line breaks from the word wrap..?

    I think not

    ..but there may be an easier way to dynamically alter dialogue box images..

    with

    Example.capx

  • Awesome, thanks a lot for this!

    I was avoiding using any height methods at first because I wasn't sure what font sizes I'd need, and I didn't want a system that would need some re-coding every time I altered my formats. But it's the next best thing.

    I'm having an issue, though. I've troubleshooted it as best I could with a friend for the last few hours and it seems to me that when I ask for the value TextHeight I get a negative version of the "Line Height" property of the Text Object.

    For example, if I have Variable=Text.TextHeight, no matter how much text is in the Text object, I'll get Variable=(-1 * "Line Height of Text"). If my Line Height for the Text Object is manually set to 12, TextHeight will return the number -12. If my Line Height is 4, I'll get -4. So there's a correlation between TextHeight and the Line Height property that is baffling me.

    It's possible I'm misunderstanding something key in the example you made for me. Any idea what I'm doing wrong?

  • Awesome, thanks a lot for this!

    I was avoiding using any height methods at first because I wasn't sure what font sizes I'd need, and I didn't want a system that would need some re-coding every time I altered my formats. But it's the next best thing.

    I'm having an issue, though. I've troubleshooted it as best I could with a friend for the last few hours and it seems to me that when I ask for the value TextHeight I get a negative version of the "Line Height" property of the Text Object.

    For example, if I have Variable=Text.TextHeight, no matter how much text is in the Text object, I'll get Variable=(-1 * "Line Height of Text"). If my Line Height for the Text Object is manually set to 12, TextHeight will return the number -12. If my Line Height is 4, I'll get -4. So there's a correlation between TextHeight and the Line Height property that is baffling me.

    It's possible I'm misunderstanding something key in the example you made for me. Any idea what I'm doing wrong?

    Turn the negative into a positive with the expression abs, abs(x) Absolute value of x e.g. abs(-5) = 5, might work

  • EDIT:

    I figured it out! I'll write what the problem was and leave the previous post below here for posterity.

    My system used a lot of invisible text objects at first, then pulled data from those. This works out for a lot of things, but for some strange reason if an object has an invisible property it hides the TextHeight from the engine. So even if you have 30 lines of 12 point text in there, if you try to draw out the TextHeight you'll end up with a funky value based on the object's Line Height.

    Not sure if this is an actual feature of the engine or not, but if anyone has trouble finding TextHeight, try making the object visible!

    (Another problem is that if the object is off-screen it might not work. This is creating more problems for me than I had hoped...)

    Thanks for all the help, you guys.

    -------PREVIOUS POST--------

    Turn the negative into a positive with the expression abs, abs(x) Absolute value of x e.g. abs(-5) = 5, might work

    Thanks for the suggestion.

    The absolute value would be a good way to craft the final equation, but the issue isn't what number is being pulled out so much as that it doesn't correlate to the amount of text shown within the object. If I have nothing written in the text object, or if I have 500 characters, I still retrieve the same value when I call TextHeight. A static value won't help me dynamically alter the size of the box.

    This is extremely weird because as I keep trying to troubleshoot the problem it looks like I'm having it only within my own project. When I try to retrieve the TextHeight value in the example Korbaach gave, the return is exactly what I'd expect. Yet in my own project, the return is definitely based on the Line Height of the object rather than the content within the rectangle.

    Searching around the forum hasn't lead me to any answers so far. If anyone recalls a thread dealing with this issue I'd love to check it out.

  • My system used a lot of invisible text objects ....

    Merlandese

    I'm sorry I did not mentioned ..TextHeight&Text.Width don't work with invisible Text object...

    but.. as you see in capx ..I use "set opacity to 0" and it works just fine...

  • No worries! It all worked and I got good practice. The opacity trick is a good one, thanks!

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