How do I use Newline in strings?

0 favourites
  • 8 posts
From the Asset Store
A collection of a mix of percussion and orchestral string loops, including 20 musical sketches.
  • 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?

  • 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..

  • 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 ? <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Wow. Good work 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 ? <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    No, I don't hate anyone..

    Is that strange?

  • 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.

  • 'twas so, at least I hope so

  • 'twas so, at least I hope so

    Lot of hoping happening here, I hope that hope brings hope..

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