How do I use Newline in strings?

Get help using Construct 2

Post » Mon Nov 02, 2015 8:05 am

Hello.

I'm setting up menus for my project. how I have it set up is I have a sprite object with two strings. It is set up so that when the mouse collides with a button it will look at it's strings to see what to make the active feature. the buttons are the same object with different frames that I will change in the layout view.

The first string tells the game what game mode the button sets up. So this string could be "KOTH, CTF, ect"

the second contains a description of the game type. a text object to the side will change to the text in this field.

The problem I'm having is when you set a string inside an instance variable, double-quotes no longer seem to work. the issue this has is the command "newline" won't work. Meaning I can't paragraph rules that change how the game flows. And I don't want it to be a contentious string.

Is there a way to have the system still look at the expressions inside an instance variable?
B
14
S
5
Posts: 54
Reputation: 1,061

Post » Mon Nov 02, 2015 8:34 am

One way to split up a string would be to use tokenat(string,index,seperator)

In the string add a separator where you'd like the newline to be:

TextVariable = "Hi everyone,\Glad to see you..\Wanna have some fun?"

on button clicked
> set text to: tokenat(Textvariable,0,"\")&newline&tokenat(Textvariable,1,"\")&newline&tokenat(Textvariable,2,"\")

the textobject would display

Hi everyone,
Glad to see you..
Wanna have some fun?

You could also use a for loop from 0 to tokencount(Textvariable,"\")-1 and set an action to append tokenat(Textvariable,loopindex,"\")&newline&

This all might sound a bit complicated, but when you get the hang of tokenat() and tokencount() , you can do so much with it..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Nov 02, 2015 8:37 am

perhaps you could use tokenat to split your text and then add in a newline as required ?

see https://www.scirra.com/manual/126/system-expressions

edit - ok so I see @LittleStain has beaten me to it again.
edit 2 - and his answer is so much more informative than mine, don't you just hate some people ? :)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Mon Nov 02, 2015 4:51 pm

Wow. Good work @LittleStain. I will need to work with this with the loop idea. Thanks a lot.

@RamPackWobble hehe Some people seem to be on top of stuff like crazy. :P
B
14
S
5
Posts: 54
Reputation: 1,061

Post » Mon Nov 02, 2015 5:32 pm

RamPackWobble wrote:perhaps you could use tokenat to split your text and then add in a newline as required ?

see https://www.scirra.com/manual/126/system-expressions

edit - ok so I see @LittleStain has beaten me to it again.
edit 2 - and his answer is so much more informative than mine, don't you just hate some people ? :)


No, I don't hate anyone..
Is that strange?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Nov 02, 2015 7:18 pm

I think he was just having a little fun (I hope so?)

but I got the loop to work. so now I can edit my description and just add the \ were I want breaks.

Thanks a ton man. that helped a lot.
B
14
S
5
Posts: 54
Reputation: 1,061

Post » Mon Nov 02, 2015 9:57 pm

'twas so, at least I hope so :)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Mon Nov 02, 2015 10:00 pm

RamPackWobble wrote:'twas so, at least I hope so :)


Lot of hoping happening here, I hope that hope brings hope.. :)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: Congrats2u and 24 guests