Dynamic setting of text.text with newline not parsing. [SOLVED]

0 favourites
  • 7 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Ok, I've tried multiple methods to do this and so far, no success.

    If I manually set the contents of a text.text to "This" & newline & "That" It properly displays: This on one line and That on a second line.

    If I try to set the text.text from a JSON.Get("MyKey") to "This" & newline & "That" I get: "This" & newline & "That"

    I have tried various combinations of removing quotes, adding quotes, etc. Whatever I do, it doesn't seem to be parsing the text field properly and adding in the newline.

    *edit*

    Ok, this was not what I expected as the answer but it works:

    I was creating a JSON in PHP and sending it back to C3 with an Ajax request and having C3 fill in the text field with the JSON value. I stupidly assumed that if I sent the text as C3 expected to find it that it would parse it and add in the newlines. It appears it does not. This solution seems to bypass the need for Construct to parse the line and properly adds in newlines.

    $jsonObject->Error = '"This" & newline & "That"'; // does not work

    $jsonObject->Error = "This\r\nThat"; //does work

  • Fengist

    newline is essentially a variable for the control character that causes a line break. So when the text is read from the jason, it only sees the characters the spell newline, not the actual control character (which is Hex 0D or something like that)...

    so, when you assign the text, you need to use Replace.

    Set Text.Text to Replace(jsontext, "newline", newline)

  • You won't be able to get expressions from a string such as you have saved in JSON.Get("MyKey"). However, if you have a text already set as "This" & newline & "That", then write the entire string from text.text to your key, it will load properly. You can also save newlines as carriage returns in word processors like word pad, and can be properly get parsed by construct as well (notepad might not work). Basically it depends on how you create or write JSON.Get("MyKey").

  • yeah, that tells php to insert the correct control characters...

  • Well, thanks for the confirmation guys. With the strange C3 conventions on adding strings and newlines together I expected it to parse the &newline& but yea, this works and I have no problem typing \r\n to make it work.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Construct could not parse string literals in the way you expected, because it would make it impossible to set some strings. For example if it parsed the string as an expression, you couldn't set a string to the word "newline", because it would interpret it as an expression and insert a newline character; you couldn't set a string to "1+1" because it would evaluate it and set it to 2; and so on...

  • Construct could not parse string literals in the way you expected, because it would make it impossible to set some strings. For example if it parsed the string as an expression, you couldn't set a string to the word "newline", because it would interpret it as an expression and insert a newline character; you couldn't set a string to "1+1" because it would evaluate it and set it to 2; and so on...

    Right, I understand the reasoning behind the parsing or lack thereof, it was just a bit unexpected. The logic I was working under was, if I set the string manually and it behaves a certain way, then when I set it dynamically, it should behave the same. I was expecting that anything within double quotes wouldn't be parsed and anything outside would.

    Now that I know the convention, it'll be easy enough to work with.

    Thanks.

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