Conditional menu-entries

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
AIL
Newbie
Posts: 4
Joined: Sat Feb 24, 2018 12:03 pm
Deviantart: xilmi
Github: Xilmi
Skype: nskail
Soundcloud: Stumpp
Contact:

Conditional menu-entries

#1 Post by AIL »

How do I create conditional menu-entries?

That is entries that are only shown when a particular condition is fulfilled.

Example that doesn't work to show what I want:

Code: Select all

          menu:
		if minerals >= 2:          
	                "Build farm [farm] (food: [food])":
        	        $ farm = farm + 1
			$ minerals = minerals - 2	
		if food >= 2:
			"Increase population (current: [population])"
			$ population = population + 1
			$ food = food - 2
Does anyone know if and how this can be accomplished?

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

Re: Conditional menu-entries

#2 Post by Ocelot »

https://www.renpy.org/doc/html/menus.html

Code: Select all

menu:
    "Build farm [farm] (food: [food])" if minerals >= 2:
        $ farm = farm + 1
        $ minerals = minerals - 2	
    "Increase population (current: [population])" if food >= 2:
        $ population = population + 1
        $ food = food - 2
< < insert Rick Cook quote here > >

AIL
Newbie
Posts: 4
Joined: Sat Feb 24, 2018 12:03 pm
Deviantart: xilmi
Github: Xilmi
Skype: nskail
Soundcloud: Stumpp
Contact:

Re: Conditional menu-entries

#3 Post by AIL »

Found it... It actually was described at the very bottom of:

https://www.renpy.org/doc/html/menus.html

Whoops, someone answered in the meantime. Thanks too!

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Conditional menu-entries

#4 Post by xavimat »

Note that you need at least one option available, otherwise the menu will be dismissed (IIRC), and the next line of the code executed, that maybe it's not what you want.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

AIL
Newbie
Posts: 4
Joined: Sat Feb 24, 2018 12:03 pm
Deviantart: xilmi
Github: Xilmi
Skype: nskail
Soundcloud: Stumpp
Contact:

Re: Conditional menu-entries

#5 Post by AIL »

xavimat wrote: Sun Feb 25, 2018 1:35 pm Note that you need at least one option available, otherwise the menu will be dismissed (IIRC), and the next line of the code executed, that maybe it's not what you want.
Skipping the menu when no option is available was indeed what I wanted. I like that it behaved that way.

Post Reply

Who is online

Users browsing this forum: Andredron