Keymap's in Ren'py
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.
Keymap's in Ren'py
Hello there. I'm trying to program a menu into my game. The menu in the game is going to have many clickable buttons, that display save options, the character profiles, items, and other miscellaneous things that involve images, text, and buttons. My my problem is, however, I want the player to be able to press a button on the key board (say A or Q) and open this menu any point during the game after they receive a specific item that will allow them access to the menu.
I have defined the menu as just an imagemap, however would it be best to define it as a screen as well? As different buttons do different things, I'm sure I'm going to have to throw a few labels in there. Also, how do I define it as a keymap with an if statement? I have a basic understanding of keymaps, however all the codes I have tried don't work out for me. They don't crash my game, they just do nothing. I may be placing them in the wrong areas, but I'm not too sure.
Sorry if this is really newbish or a bit much, it's just the keymap programming that's giving me a hard time ^^;
I have defined the menu as just an imagemap, however would it be best to define it as a screen as well? As different buttons do different things, I'm sure I'm going to have to throw a few labels in there. Also, how do I define it as a keymap with an if statement? I have a basic understanding of keymaps, however all the codes I have tried don't work out for me. They don't crash my game, they just do nothing. I may be placing them in the wrong areas, but I'm not too sure.
Sorry if this is really newbish or a bit much, it's just the keymap programming that's giving me a hard time ^^;
- Divona
- Miko-Class Veteran
- Posts: 678
- Joined: Sun Jun 05, 2016 8:29 pm
- Completed: The Falconers: Moonlight
- Organization: Bionic Penguin
- itch: bionicpenguin
- Contact:
Re: Keymap's in Ren'py
I want the player to be able to press a button on the key board (say A or Q) and open this menu any point during the game after they receive a specific item that will allow them access to the menu.
To add the key to be functional permanently:
I have written the code above from my memory, and have not check it in Ren'Py, but it's something like that.
Have you look at using 'key' in screens?
https://www.renpy.org/doc/html/screens.html#key
There also 'Customizing the Keymap' in documentation if you want to add custom keys to the list.
https://www.renpy.org/doc/html/keymap.html#keymap
To add the key to be functional permanently:
Code: Select all
define player_has_item = True
init python:
# Define function to open the menu
def show_pause_menu():
if player_has_item == True:
renpy.call_screen("my_pause_menu")
# Add key to 'open_pause_menu', this case is 'a' on keyboard
config.keymap["open_pause_menu"] = ["a"]
# When key is pressed at anytime, open custom screen.
config.underlay.append(renpy.Keymap(open_pause_menu=show_pause_menu))
......
screen my_pause_menu():
......
Have you look at using 'key' in screens?
https://www.renpy.org/doc/html/screens.html#key
There also 'Customizing the Keymap' in documentation if you want to add custom keys to the list.
https://www.renpy.org/doc/html/keymap.html#keymap
Re: Keymap's in Ren'py
Thank you for the speedy response!
I tried the code you provided, and it worked, thank you so much! But, if you don't mind, I have two questions about it.
How do I make it so the menu (Which I have defined as a screen) covers the text box? If that is possible.
The second question being, there seems to be a delay as I bring up the screen. I press "a" then I have to click the screen (or press Enter) in order for the menu to show up, which messes with the dialogue. Is there a way to make it that the instant I press "a" the menu comes up?
I have looked at both pages. I've tried using these documents as examples for my coding, but they they produced no results.Have you look at using 'key' in screens?
https://www.renpy.org/doc/html/screens.html#key
There also 'Customizing the Keymap' in documentation if you want to add custom keys to the list.
https://www.renpy.org/doc/html/keymap.html#keymap
I tried the code you provided, and it worked, thank you so much! But, if you don't mind, I have two questions about it.
How do I make it so the menu (Which I have defined as a screen) covers the text box? If that is possible.
The second question being, there seems to be a delay as I bring up the screen. I press "a" then I have to click the screen (or press Enter) in order for the menu to show up, which messes with the dialogue. Is there a way to make it that the instant I press "a" the menu comes up?
- Divona
- Miko-Class Veteran
- Posts: 678
- Joined: Sun Jun 05, 2016 8:29 pm
- Completed: The Falconers: Moonlight
- Organization: Bionic Penguin
- itch: bionicpenguin
- Contact:
Re: Keymap's in Ren'py
You will need to set zorder. Probably set it to 100 or something.Wildmask wrote:How do I make it so the menu (Which I have defined as a screen) covers the text box? If that is possible.
https://www.renpy.org/doc/html/screens. ... -statement
Try set modal to True also?Wildmask wrote:The second question being, there seems to be a delay as I bring up the screen. I press "a" then I have to click the screen (or press Enter) in order for the menu to show up, which messes with the dialogue. Is there a way to make it that the instant I press "a" the menu comes up?
Code: Select all
modal True
Code: Select all
define player_has_item = True
init python:
# Define function to open the menu
def show_pause_menu():
if player_has_item == True:
renpy.call_in_new_context("display_pause_menu")
# Add key to 'open_pause_menu', this case is 'a' on keyboard
config.keymap["open_pause_menu"] = ["a"]
# When key is pressed at anytime, open custom screen.
config.underlay.append(renpy.Keymap(open_pause_menu=show_pause_menu))
......
label display_pause_menu:
call screen my_pause_menu
......
screen my_pause_menu():
......
Code: Select all
define config.enter_transition = None
define config.exit_transition = None
Re: Keymap's in Ren'py
I added zorder and modal True to the code, and it worked! Thank you for the big help!
I just have one last small question, what command would I use to let it so when the player presses, for example, "q", it closes the menu? It sounds really simple but I've tried multiple codings of config.keymap and I can't seem to figure it out.
I just have one last small question, what command would I use to let it so when the player presses, for example, "q", it closes the menu? It sounds really simple but I've tried multiple codings of config.keymap and I can't seem to figure it out.
- Divona
- Miko-Class Veteran
- Posts: 678
- Joined: Sun Jun 05, 2016 8:29 pm
- Completed: The Falconers: Moonlight
- Organization: Bionic Penguin
- itch: bionicpenguin
- Contact:
Re: Keymap's in Ren'py
Would this work?:
Code: Select all
screen my_pause_menu():
key "q" action renpy.hide_screen
......
Re: Keymap's in Ren'py
Apparently not. When inputting this, the game works fine until I go to press "q" to exit the menu. At which point I'm given this error:Divona wrote:Would this work?:Code: Select all
screen my_pause_menu(): key "q" action renpy.hide_screen ......
Code: Select all
store._return = renpy.call_screen(name, *args, **kwargs)
TypeError: hide_screen() takes at least 1 argument (0 given)
Code: Select all
AttributeError: 'module' object has no attribute 'hide_screen_MyScreen'
- Divona
- Miko-Class Veteran
- Posts: 678
- Joined: Sun Jun 05, 2016 8:29 pm
- Completed: The Falconers: Moonlight
- Organization: Bionic Penguin
- itch: bionicpenguin
- Contact:
Re: Keymap's in Ren'py
Code: Select all
screen my_pause_menu():
tag custom_menu
key "q" action Function(renpy.hide_screen, "custom_menu")
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Keymap's in Ren'py
Wildmask. You are using screen actions. All the screen actions are documented here: https://www.renpy.org/doc/html/screen_actions.html
The action you want is not Function, but Hide
You may want to look at that page in general to see the different options you have available
The action you want is not Function, but Hide
Code: Select all
screen my_pause_menu():
key "q" action Hide("custom_menu")
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
Re: Keymap's in Ren'py
trooper6 wrote:Wildmask. You are using screen actions. All the screen actions are documented here: https://www.renpy.org/doc/html/screen_actions.html
The action you want is not Function, but Hide
You may want to look at that page in general to see the different options you have availableCode: Select all
screen my_pause_menu(): key "q" action Hide("custom_menu")
I tested them and they both work, thank you so much for the help!Divona wrote:Code: Select all
screen my_pause_menu(): tag custom_menu key "q" action Function(renpy.hide_screen, "custom_menu")
Who is online
Users browsing this forum: Bing [Bot], Google [Bot]