Group if conditions with brackets?

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
User avatar
lking22
Regular
Posts: 50
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

Group if conditions with brackets?

#1 Post by lking22 »

Not sure if this is supposed to be obvious, but is it possible to group conditions in an if statement? For an example with pseudo-code, say I wanted a menu option to be available if you were Joan's friend, or if you were Bill's friend but not Kate's friend. Would it work like this:

Code: Select all

menu:
	"Option" if (joan_friend == True) or (bill_friend == True and kate_friend == False):
		# Result of picking this choice
Or is there some other way to write it?
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

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

Re: Group if conditions with brackets?

#2 Post by Ocelot »

Yes. This will work.

Pet peeve: do not compare boolean variables to True and False. It is useless, tautological and against PEP8 (Python style guide). Your code is identical to:

Code: Select all

menu:
	"Option" if joan_friend or (bill_friend and not kate_friend):
		# Result of picking this choice
< < insert Rick Cook quote here > >

User avatar
lking22
Regular
Posts: 50
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

Re: Group if conditions with brackets?

#3 Post by lking22 »

Thank you!
Ocelot wrote: Mon Dec 11, 2017 2:02 pm Pet peeve: do not compare boolean variables to True and False. It is useless, tautological and against PEP8 (Python style guide). Your code is identical to:
Woops, guess I need to go fix... a LOT of code, heh.
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

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

Re: Group if conditions with brackets?

#4 Post by Imperf3kt »

You can shortcut the job.

Make a backup first, then use edit > search and replace (or find or similar)
In the to be replaced text, type:
= True
And leave the replaced text blank.

This can potentially screw up other stuff though, so check your game (in full) after doing this
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: No registered users