loop labels and menus [solved]
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.
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.
- pucedragonlord
- Regular
- Posts: 159
- Joined: Wed May 09, 2012 2:49 am
- Projects: The Diviner
- Organization: Two Crowns Entertainment
- Location: Now: Charlottesville, VA
- Contact:
loop labels and menus [solved]
So I've got more than a couple labels full of menus that loop back on themselves. Remembering each choice and changing the dialog to avoid players going through different menu options this way is nice and all, but I wonder if there's a way for RenPy to remember which menu choice was picked last and automatically route to that one without defining labels and variables all over the place. Just something I'm curious about. It'd be a nice feature.
Last edited by pucedragonlord on Thu Nov 08, 2012 4:39 pm, edited 1 time in total.
The more you know
- PyTom
- Ren'Py Creator
- Posts: 15893
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: loop labels and menus
Do you want to avoid showing them, or automatically select them? I'm not clear on what you want.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom
- pucedragonlord
- Regular
- Posts: 159
- Joined: Wed May 09, 2012 2:49 am
- Projects: The Diviner
- Organization: Two Crowns Entertainment
- Location: Now: Charlottesville, VA
- Contact:
Re: loop labels and menus
automatically select them. Sorry about that, guess it wasn't that clear.
The more you know
-
Kinsman
- Regular
- Posts: 130
- Joined: Sun Jul 26, 2009 7:07 pm
- Location: Fredericton, NB, Canada
- Contact:
Re: loop labels and menus
You can use Python code to show menus using renpy.display_menu(), and then wrap some code around that to get the effect you want.
Is this what you're looking for?
Is this what you're looking for?
Code: Select all
label start:
# These variables are used by the menu system. Initialize them at game start.
$menuspicked = {}
$choice = ""
call test
return
# Here's a wrapper around renpy.display_menu. It will display a menu if the ID for that menu seems new, or else just return what the player chose if that menu has been shown before.
label smartmenu(*items):
python:
choice = ""
if items[0] in menuspicked:
choice = menuspicked[items[0]]
elif len(items) == 1:
pass
else:
# construct a menu
menuitems = []
for i in range(1,len(items)):
menuitems.append((items[i],items[i]))
choice = renpy.display_menu(menuitems)
menuspicked[items[0]] = choice
return
# Here's an example of how to use it.
label inforequest:
call smartmenu("INFO","Neo-Africa","World War III","Zombie Outbreak")
if choice == "Neo-Africa":
"Neo Africa was the confederation of most African nations in 2024."
if choice == "World War III":
"World War III was a conventional war between Russia and China. NATO chose to stay out of it."
if choice == "Zombie Outbreak":
"America had its own problems during World War III, what with the zombies and all."
return
label test:
"OK, what part of the future would you like to know about? One choice only, please."
call inforequest
"And let me repeat that, to make sure you remember:"
call inforequest
return
Flash To Ren'Py Exporter
See the Cookbook thread
See the Cookbook thread
- pucedragonlord
- Regular
- Posts: 159
- Joined: Wed May 09, 2012 2:49 am
- Projects: The Diviner
- Organization: Two Crowns Entertainment
- Location: Now: Charlottesville, VA
- Contact:
Re: loop labels and menus
that works great. Can I still have an information line showing with this menu like normal ones?
for example:
or is that not possible? If not that's fine, just curious if it's possible. When I ran it the first "INFO" line didn't show up. I assumed that's what it would do.
for example:
Code: Select all
menu:
"what do?"
"item1":
jump item1
"item2":
pass
The more you know
-
Kinsman
- Regular
- Posts: 130
- Joined: Sun Jul 26, 2009 7:07 pm
- Location: Fredericton, NB, Canada
- Contact:
Re: loop labels and menus
The "INFO" part is meant as an ID-code, so that the script knows how to keep track of which menu has been shown or not.pucedragonlord wrote:that works great. Can I still have an information line showing with this menu like normal ones?
for example:or is that not possible? If not that's fine, just curious if it's possible. When I ran it the first "INFO" line didn't show up. I assumed that's what it would do.Code: Select all
menu: "what do?" "item1": jump item1 "item2": pass
Here, let me improve the code a little.
Code: Select all
label smartmenu(*items):
python:
choice = ""
menukey = ""
for i in range(0,len(items)):
menukey = menukey + items[i]
if menukey in menuspicked:
choice = menuspicked[menukey]
elif len(items) == 1:
pass
else:
# construct a menu
menuitems = []
for i in range(1,len(items)):
menuitems.append((items[i],items[i]))
renpy.say(None,items[0],interact=False)
choice = renpy.display_menu(menuitems)
menuspicked[menukey] = choice
return
Flash To Ren'Py Exporter
See the Cookbook thread
See the Cookbook thread
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot]
