Better way of string concatenation / joining?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
renpycoder
Newbie
Posts: 7
Joined: Fri Mar 09, 2018 12:58 am
Contact:

Better way of string concatenation / joining?

#1 Post by renpycoder » Sat Mar 10, 2018 9:54 pm

My visual novel involves third person point of view. I just noticed that in renpy, let's say you want something like this:

"Hey, I can't do that!", said Johnny.

^ This right here is hard to execute. If we do use ' ' around the " ", it can't be because you're using another single comma ( ' ) as an apostrophe.

Is there a better way of dealing with this?

Thanks in advance!

User avatar
Milkymalk
Miko-Class Veteran
Posts: 752
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Better way of string concatenation / joining?

#2 Post by Milkymalk » Sat Mar 10, 2018 10:42 pm

You can use backslash \ as an escape character, so \' will work as a ' inside ' '.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Better way of string concatenation / joining?

#3 Post by Imperf3kt » Sun Mar 11, 2018 1:13 am

Another practise is simply to do things like this:

Code: Select all

'"Hey, I can't do that!", said Johnny.'
You'll notice I used ' to open and close the statement.

I usually use a mixture, so I can't say which is 'better' than the other, but both ways will work.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Better way of string concatenation / joining?

#4 Post by Ocelot » Sun Mar 11, 2018 1:24 am

Imperf3kt wrote:
Sun Mar 11, 2018 1:13 am
Another practise is simply to do things like this:

Code: Select all

'"Hey, I can't do that!", said Johnny.'
You'll notice I used ' to open and close the statement.

I usually use a mixture, so I can't say which is 'better' than the other, but both ways will work.
And you might notice, that another single quote inside string breaks this statement. And, for some reason, RenPy does not supports triple-quoted strings.

I feel like line example in Creator-Defined Statements is exactly what is needed here:
https://www.renpy.org/doc/html/cds.html#example
< < insert Rick Cook quote here > >

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Better way of string concatenation / joining?

#5 Post by Imperf3kt » Sun Mar 11, 2018 3:35 am

Oh right, I totally missed that. In that case, yeah, use backslashes or atleast escape the apostriphied "can't"
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]