How do I format Ajax impored text

Get help using Construct 2

Post » Sun Mar 18, 2018 8:15 am

Hi everyone,

What do I use to add linebreaks in text that I import from a json file?
When I use "some text" & newline the import breaks.
B
18
S
9
Posts: 272
Reputation: 2,363

Post » Sun Mar 18, 2018 9:14 am

facecrime wrote:Hi everyone,

What do I use to add linebreaks in text that I import from a json file?
When I use "some text" & newline the import breaks.

You can use tokenat to put line breaks into your text.

So if your separator is "|" put that character in your text where you want line breaks. Then you can say something like:

set text to: tokenat("some text",0,"|")&newline&tokenat("some text",1,"|")
B
80
S
55
G
70
Posts: 450
Reputation: 43,632

Post » Sun Mar 18, 2018 9:50 am

@Artpunk Good idea, thanks!
B
18
S
9
Posts: 272
Reputation: 2,363

Post » Mon Mar 19, 2018 8:17 pm

@Artpunk
hm, so here I am trying to replace placeholder characters with linebreaks in my imported array.
I seem to not get the syntax right, what I do is:

On Ajax import complete:
for each X element: set value at LOOPINDEX to replace( str(Array.At(LOOPINDEX), "|", "&newline&" )

not sure about array expressions ... can someone enlighten me, what's wrong here?
B
18
S
9
Posts: 272
Reputation: 2,363

Post » Tue Mar 20, 2018 1:59 am

It's easier to use replace() expression:

Set s to "Hi there!^How are you?^Take a seat."
Set s to replace(s, "^", newline)
Last edited by dop2000 on Wed Mar 21, 2018 2:54 am, edited 1 time in total.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
156
Posts: 2,204
Reputation: 82,989

Post » Tue Mar 20, 2018 8:13 pm

hey @dop2000 !
yeah, thats what i do, i just now figured out what i had missed: I am in fact using two dimensions, hence i needed to fix the index.

new problem now, to insert a linebreak in a string i need to interrupt the string.
how do i get quotes attached before and after &newline& ?
B
18
S
9
Posts: 272
Reputation: 2,363

Post » Wed Mar 21, 2018 3:02 am

I don't understand your question. Why do you need quotes?
Your source string is this:

sourceString= "Lorem ipsum dolor sit amet.&newline&Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.&newline&Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.&newline&Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

You do
set targetString to replace(sourceString, "&newline&", newline)


And when you display targetString on the screen, there should be line breaks where needed.
B
17
S
9
G
156
Posts: 2,204
Reputation: 82,989


Return to How do I....?

Who is online

Users browsing this forum: draiza and 5 guests