Help on simplifying conditional dialogue choice branches?

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
Ilysis
Newbie
Posts: 2
Joined: Thu Aug 27, 2020 12:28 am
Contact:

Help on simplifying conditional dialogue choice branches?

#1 Post by Ilysis » Thu Aug 27, 2020 12:51 am

Wasn't really sure how to word the topic, but basically, my game is a short dating sim with five characters with a good number of different endings depending on what you do in each characters' paths and who you rank up with.
It also involves any of the candidates being made unavailable to interact with as a result of the player reacting badly to them.

In both instances, I have a problem... the "if-then" branch count is huge on both ends, making the script very cluttered and confusing.
I tried doing something like

Code: Select all

menu:
  if charRoute != -1:
    "Go with Char"
  
  if dharRoute != -1:
    "Go with Dhar"
but this just gives me an "ExpectedMenuItem" error.

Does anybody know if there is a way I can simplify this and how?
Thank you.
Attachments
Cluttered menu script 2.png
Cluttered menu script 1.png

User avatar
namastaii
Eileen-Class Veteran
Posts: 1348
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Help on simplifying conditional dialogue choice branches?

#2 Post by namastaii » Thu Aug 27, 2020 2:30 am

I would have one menu and put all the conditionals inside that menu

User avatar
HEXdidnt
Newbie
Posts: 16
Joined: Tue Aug 11, 2020 1:25 pm
Projects: A Night at the Office, Embracing Christmas
Deviantart: HEXdidnt
Location: Harrow, London, UK
Contact:

Re: Help on simplifying conditional dialogue choice branches?

#3 Post by HEXdidnt » Thu Aug 27, 2020 4:37 am

Not sure I'm interpreting your variables right, but you can add your if statements to each menu item, such that it will only be displayed on screen if those conditions are met. Something like:

Code: Select all

menu:
	"Chizza" if croute >= 1:
		jump chizzaEnding
	"Macy" if froute >= 1:
		jump macyEnding
	"Mariel" if droute >= 1:
		jump marielEnding
	"Edna" if nroute >= 1:
		jump ednaEnding
	"Chizza and Macy" if croute >=1 and froute >=1:
		jump chizzaMacyEnding
	"Chizza and Mariel" if croute >=1 and droute >=1:
		jump chizzaMarielEnding
	"Chizza and Edna" if croute >=1 and nroute >=1:
		jump chizzaEdnaEnding
	"Macy and Mariel" if froute >=1 and droute >=1:
		jump macyMarielEnding
	"Macy and Edna" if froute >=1 and nroute >=1:
		jump macyEdnaEnding
	"Mariel and Edna" if droute >=1 and nroute >=1:
		jump marielEdnaEnding
It's still going to end up pretty long code-wise, depending on how many characters you have but, on the upside, as you list the pairings, there's one fewer each time, since the preceding characters have already dealt with some of the permutations.

I'm still wrapping my head around menus myself, but I think the 'unexpected menu item' is the if statement preceeding the menu item.
As ever, dropping litter in the zen garden of your mind...

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

Re: Help on simplifying conditional dialogue choice branches?

#4 Post by philat » Thu Aug 27, 2020 7:04 am

HEXdidnt is correct, but looking at your logic, I would say pulling the logic out into python entirely and generating the menu programmatically would also be beneficial.

Code: Select all

# logic goes here - do whatever needs to be done, return the list of possible options

$ returned_list = ["Chizza", "Macy", "Edna"] # is whatever you set it to from the logic above, here we assume it's ["Chizza", "Macy", "Edna"]
$ renpy.say(None, "Choose an ending", interact=False) # creates a caption for your menu
$ result = menu([(x, x) for x in returned_list], screen="choice") # this creates a menu that will return either "Chizza", "Macy", or "Edna"
jump expression result+"Ending" # this would jump to ChizzaEnding or MacyEnding or EdnaEnding / obviously you would need to name the labels in a manner where this is possible
You also don't need to necessarily feel like you need to use the in-built menu -- you could just as well create a separate screen with Jump() options based on the returned list. Of course, feel free to ignore if you're more comfortable using renpy script menus.

Ilysis
Newbie
Posts: 2
Joined: Thu Aug 27, 2020 12:28 am
Contact:

Re: Help on simplifying conditional dialogue choice branches?

#5 Post by Ilysis » Thu Aug 27, 2020 2:10 pm

Ooh, these help a lot! Thank you guys very much!

Post Reply

Who is online

Users browsing this forum: Google [Bot]