How do I detect line breaks from CSV data?

Get help using Construct 2

Post » Fri Sep 25, 2015 2:06 am

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!
B
24
S
6
G
6
Posts: 17
Reputation: 4,458

Post » Fri Sep 25, 2015 10:24 am

Merlandese wrote: 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
Image

Example.capx


Image
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sat Sep 26, 2015 2:13 am

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?
B
24
S
6
G
6
Posts: 17
Reputation: 4,458

Post » Sat Sep 26, 2015 7:19 am

Merlandese wrote: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
Bushy Ball\Boatman Bill\Sticky Web\Snake

Image ImageImageImage

During the gold rush it was a good time to be in the pick and shovel business
B
47
S
14
Posts: 253
Reputation: 5,389

Post » Sat Sep 26, 2015 10:53 pm

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--------
sizcoz wrote: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. :)
B
24
S
6
G
6
Posts: 17
Reputation: 4,458

Post » Sun Sep 27, 2015 10:00 am

Merlandese wrote: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...

Image
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sun Sep 27, 2015 7:33 pm

No worries! It all worked and I got good practice. The opacity trick is a good one, thanks!
B
24
S
6
G
6
Posts: 17
Reputation: 4,458


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, wertt22 and 32 guests