Page 1 of 1
loop labels and menus [solved]
Posted: Wed Oct 31, 2012 7:52 pm
by pucedragonlord
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.
Re: loop labels and menus
Posted: Wed Oct 31, 2012 9:08 pm
by PyTom
Do you want to avoid showing them, or automatically select them? I'm not clear on what you want.
Re: loop labels and menus
Posted: Thu Nov 01, 2012 1:23 pm
by pucedragonlord
automatically select them. Sorry about that, guess it wasn't that clear.
Re: loop labels and menus
Posted: Thu Nov 01, 2012 5:42 pm
by Kinsman
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?
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
Re: loop labels and menus
Posted: Mon Nov 05, 2012 6:16 pm
by pucedragonlord
that works great. Can I still have an information line showing with this menu like normal ones?
for example:
Code: Select all
menu:
"what do?"
"item1":
jump item1
"item2":
pass
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.
Re: loop labels and menus
Posted: Tue Nov 06, 2012 4:15 pm
by Kinsman
pucedragonlord wrote:that works great. Can I still have an information line showing with this menu like normal ones?
for example:
Code: Select all
menu:
"what do?"
"item1":
jump item1
"item2":
pass
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.
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.
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
Now, the first item will be what appears as the question that goes with the menu. The ID code is now auto-generated based on what's in the menu, so you won't need to worry about it unless your menus are very similar to each other.