Menu choices that change depending on a setting? 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.
- Aviala
- Miko-Class Veteran
- Posts: 533
- Joined: Tue Sep 03, 2013 8:40 am
- Completed: Your Royal Gayness, Love Bug, Lovingly Evil
- Organization: Lizard Hazard Games
- Tumblr: lizardhazardgames
- itch: aviala
- Location: Finland
- Contact:
Menu choices that change depending on a setting? SOLVED
Hey all!
I want to include an option in my game that lets the player choose whether menu choices show which resources it affects.
Like if there is a choice "Give alms to the poor" it would also show an image of a coin to indicate that your Wealth resource is affected. But I want an option to turn the coin icon on/off since different players prefer different things - some want to be surprised, and some want to balance their resources as efficiently as possible.
How would I do that? Is it possible to include if statements inside a menu option? Something like this?
menu:
"Give alms to the poor" if option == True: {image=coin.png}
I assume this doesn't work as-is, could someone help me out?
I want to include an option in my game that lets the player choose whether menu choices show which resources it affects.
Like if there is a choice "Give alms to the poor" it would also show an image of a coin to indicate that your Wealth resource is affected. But I want an option to turn the coin icon on/off since different players prefer different things - some want to be surprised, and some want to balance their resources as efficiently as possible.
How would I do that? Is it possible to include if statements inside a menu option? Something like this?
menu:
"Give alms to the poor" if option == True: {image=coin.png}
I assume this doesn't work as-is, could someone help me out?
Last edited by Aviala on Fri Sep 22, 2017 10:56 am, edited 1 time in total.
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3791
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Menu choices that change depending on a setting?
If I'm understanding this correctly, you want to set an inline image in a choice menu by conditionals?
Sure that should work.
Just rearrange your if statement:
Sure that should work.
Just rearrange your if statement:
Code: Select all
label mygame:
menu:
if option == True:
"Give alms to the poor {image=coin.png}":
call my_function
else:
"Give alms to the poor":
call my_function
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
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Menu choices that change depending on a setting?
You can also alter the choice screen code itself. I'd model it off of code discussed in this and related threads: viewtopic.php?f=8&t=25453&p=313338
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
-
- Regular
- Posts: 91
- Joined: Mon Jul 31, 2017 8:33 am
- Deviantart: LedianWithACamera
- Contact:
Re: Menu choices that change depending on a setting?
If you wanted something less complex then making the choices appear and disappear, just have multiple menus.
Less refined but kinda easier to understand? You wouldn't have to worry about the image accidentally being on when its supposed to be off or vice versa if it cant ever be on in one and ever be off in the other.
Code: Select all
"Hi this is the text before the menu."
if $ variable 1 == on
jump menu1
else
jump menu2
label menu1
"Yes"
menu stuff
"No"
menu stuff
label menu2
"Yes with image!"
menu stuff
"No"
menu stuff
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3791
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Menu choices that change depending on a setting?
This does exactly the opposite of what is advertised. This is just a more complex way of doing the same thing shown in my reply.TheChatotMaestro wrote: ↑Mon Sep 04, 2017 7:53 pm If you wanted something less complex then making the choices appear and disappear, just have multiple menus.Less refined but kinda easier to understand? You wouldn't have to worry about the image accidentally being on when its supposed to be off or vice versa if it cant ever be on in one and ever be off in the other.Code: Select all
"Hi this is the text before the menu." if $ variable 1 == on jump menu1 else jump menu2 label menu1 "Yes" menu stuff "No" menu stuff label menu2 "Yes with image!" menu stuff "No" menu stuff
IMO, you've made it unnecessarily complicated.
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
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Re: Menu choices that change depending on a setting?
This doesn't work, because menu doesn't process ifs -- if you run this, this simply throws an error (expected menuitem).Imperf3kt wrote: ↑Mon Sep 04, 2017 3:36 pmCode: Select all
label mygame: menu: if option == True: "Give alms to the poor {image=coin.png}": call my_function else: "Give alms to the poor": call my_function
Code: Select all
menu:
"Give alms to the poor {image=coin.png}" if option:
"blahblah with image"
Give alms to the poor" if not option:
"blahblah without image"
The thread (and related threads) trooper references would require some up-front set up but would be easier to use down the line.
Code: Select all
menu:
"Give alms to the poor (coin)":
"blahblah"
screen choice:
# conceptually, if option, replace (coin) with {image=coin.png} or separately add "coin.png", whatever floats your boat
# else replace (coin) with blank space
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3791
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Menu choices that change depending on a setting?
It does?
Could have sworn I'd used such a thing before, but checking what scripts I still have on me confirms that I am very likely wrong.
So please disregard my prior answer. It is incorrect and misleading.
Could have sworn I'd used such a thing before, but checking what scripts I still have on me confirms that I am very likely wrong.
So please disregard my prior answer. It is incorrect and misleading.
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
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Menu choices that change depending on a setting?
Another alternative is to declare your own custom text tag and run a function to return the correct string/icon/whatever
Semi simplified code:
A little code tidying wouldn't go amiss there... I based it on some other code which had more dictionary keys. You wouldn't really need False as the function checks the show_icons variable anyway...
Semi simplified code:
Code: Select all
init python:
menu_icon_names = ['coin', 'food', 'water']
# this just builds a dictionary for the above keys with True pointing at an icon
menu_icons_map = {k: {True:'images/icons/{0}.png'.format(k), False:''} for k in menu_icon_names}
show_icons = True
# basically interprets the {menu_icon=???} text tag and slips in an image if needed
def get_menu_icon(tag, argument, contents):
type, icon_str = renpy.TEXT_TEXT, ''
if show_icons:
icon_str = 'No icon defined for {0}'.format( argument )
if menu_icons_map.has_key( argument ) and menu_icons_map[ argument ].has_key( show_icons ):
d = renpy.easy.displayable( menu_icons_map[ argument ][ show_icons ] )
type, icon_str = renpy.TEXT_DISPLAYABLE, d
return [ ( type, icon_str ) ]
config.custom_text_tags["menu_icon"] = get_menu_icon
label start:
# debug line to check dictionary
$ k = str(menu_icons_map).replace('{', '{{').replace('[','[[')
"Icons Dict [k]"
menu:
"Icon: {menu_icon=coin}{/menu_icon}":
jump coin_label
"Choice with icon {menu_icon=food}{/menu_icon}":
jump food_label
"Second Line"
"Last Line"
return
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
- Aviala
- Miko-Class Veteran
- Posts: 533
- Joined: Tue Sep 03, 2013 8:40 am
- Completed: Your Royal Gayness, Love Bug, Lovingly Evil
- Organization: Lizard Hazard Games
- Tumblr: lizardhazardgames
- itch: aviala
- Location: Finland
- Contact:
Re: Menu choices that change depending on a setting?
Thanks guys, I'm not a very experienced coder but I think I'll try fiddling with the choice screen code. We have a lot of choices and it seems like this would make them a lot faster to code.
Remix, your suggestion is a bit hard for me to understand since I don't know a lot of Python, so I think I'll try the other suggestions first. But it's good to have multiple solutions in case I can't make some of them work. :)
Remix, your suggestion is a bit hard for me to understand since I don't know a lot of Python, so I think I'll try the other suggestions first. But it's good to have multiple solutions in case I can't make some of them work. :)
- Aviala
- Miko-Class Veteran
- Posts: 533
- Joined: Tue Sep 03, 2013 8:40 am
- Completed: Your Royal Gayness, Love Bug, Lovingly Evil
- Organization: Lizard Hazard Games
- Tumblr: lizardhazardgames
- itch: aviala
- Location: Finland
- Contact:
Re: Menu choices that change depending on a setting?
Hey all, just wanted to give a little update. I managed to somehow make it work. As I mentioned before, I'm still a beginner at coding, so the following code probably could be prettier. But it works!
Basically, now when I write (wealth) at the end of the choice text, it displays an image of a coin, and if the option is turned off, it doesn't display the coin image - exactly what I wanted!
Basically, now when I write (wealth) at the end of the choice text, it displays an image of a coin, and if the option is turned off, it doesn't display the coin image - exactly what I wanted!
Code: Select all
screen choice(items):
style_prefix "choice"
vbox:
for i in items:
if i.action:
textbutton i.caption action i.action
if "(wealth)" in i.caption:
if icons == True:
$ i.caption = i.caption.replace("(wealth)", "{image=images/coin.png}")
else:
$ i.caption = i.caption.replace("(wealth)", " ")
if "(happiness)" in i.caption:
if icons == True:
$ i.caption = i.caption.replace("(happiness)", "{image=images/smiley.png}")
else:
$ i.caption = i.caption.replace("(happiness)", " ")
if "(loyalty)" in i.caption:
if icons == True:
$ caption = caption.replace("(loyalty)", "{image=images/crown.png}")
else:
$ caption = caption.replace("(loyalty)", " ")
if "(army)" in i.caption:
if icons == True:
$ caption = caption.replace("(army)", "{image=images/sword.png}")
else:
$ caption = caption.replace("(army)", " ")
else:
pass
else:
pass
Who is online
Users browsing this forum: Majestic-12 [Bot]