Inline IF possible in a sayer string?

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
Jezzy
Regular
Posts: 30
Joined: Wed Jun 21, 2017 2:18 pm
Contact:

Inline IF possible in a sayer string?

#1 Post by Jezzy » Tue May 07, 2019 8:59 am

Hello!

I was wondering if it was possible to add a inline if to a sayer string?

For example, if I want my sayer to say there is 2 apples, I would like to add a "s" to apple if apple is more than 2.

myCharacter "There is " + str("s" if apple > 1) + " in the basket"

How can I do this in Renpy? :)

Thanks!

User avatar
nature1996
Regular
Posts: 62
Joined: Wed Jun 21, 2017 10:35 am
Contact:

Re: Inline IF possible in a sayer string?

#2 Post by nature1996 » Tue May 07, 2019 9:11 am

This might help, with an example for your case: https://www.renpy.org/doc/html/text.htm ... ating-data

Code: Select all

if apple>1:
	$ s="s"
else:
	$s=""
myCharacter "There is [apple] apple[s] in my bag."
There might be other ways
Je parle aussi français

Jezzy
Regular
Posts: 30
Joined: Wed Jun 21, 2017 2:18 pm
Contact:

Re: Inline IF possible in a sayer string?

#3 Post by Jezzy » Tue May 07, 2019 9:31 am

Thank you.

philat
Eileen-Class Veteran
Posts: 1853
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Inline IF possible in a sayer string?

#4 Post by philat » Tue May 07, 2019 9:20 pm

If you prefer, you can also use python rather than renpy statements.

Code: Select all

$myCharacter("There {0} {1} apple{2} in the basket.".format("are" if apple==0 or apple>=2 else "is", apple, "s" if apple==0 or apple>=2 else ""))

Post Reply

Who is online

Users browsing this forum: No registered users