Trying to temporarily disable some key bindings

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
User avatar
parttimestorier
Veteran
Posts: 429
Joined: Thu Feb 09, 2017 10:29 pm
Completed: No Other Medicine, Well Met By Moonlight, RE:BURN, The Light at the End of the Ocean, Take A Hike!, Wizard School Woes
Projects: Seeds of Dreams
itch: janetitor
Location: Canada
Contact:

Trying to temporarily disable some key bindings

#1 Post by parttimestorier »

I would like to temporarily make some keyboard shortcuts unusable for a brief section of my game before making them usable again afterward. I've looked at the keymap documentation and I know which specific ones I'll need to disable, but I'm not sure what the best way is to do it. I found this old thread in which people talked about doing something similar, but I'm not sure if either of those solutions would work for me. One person's suggestion in that thread is disabling shortcuts by default from the beginning, and then making a screen that returns them later on. But I want those shortcuts to be available from the beginning and for the majority of the game, then just briefly become unusable for one little bit in the middle before coming back again. And the other person shows how to disable a key binding for one screen in particular, but I want to have other stuff going on that isn't just one screen during the time when the shortcuts are disabled. Is there any other possible way to temporarily turn off some key bindings and then turn them back on?
ImageImageImage

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Trying to temporarily disable some key bindings

#2 Post by trooper6 »

You want to follow xavimat's suggestion. Make a screen, and on that screen put:

Code: Select all

screen my_key()s:
    key "h" action NullAction()
Add whatever keys you want to disable on that screen...add all of them to that screen.
Then in your game, when you don't want the keys usable in your game, show the screen and none of those keys will do anything. When you want the keys usable again, then you hide the screen.

Having this one screen shown won't stop you from showing other screens or doing other things...it is just that while your my_key screen is being shown the keys you don't want to do anything won't do anything.
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

User avatar
parttimestorier
Veteran
Posts: 429
Joined: Thu Feb 09, 2017 10:29 pm
Completed: No Other Medicine, Well Met By Moonlight, RE:BURN, The Light at the End of the Ocean, Take A Hike!, Wizard School Woes
Projects: Seeds of Dreams
itch: janetitor
Location: Canada
Contact:

Re: Trying to temporarily disable some key bindings

#3 Post by parttimestorier »

trooper6 wrote: Tue Aug 13, 2019 7:56 pm You want to follow xavimat's suggestion. Make a screen, and on that screen put:

Code: Select all

screen my_key()s:
    key "h" action NullAction()
Add whatever keys you want to disable on that screen...add all of them to that screen.
Then in your game, when you don't want the keys usable in your game, show the screen and none of those keys will do anything. When you want the keys usable again, then you hide the screen.

Having this one screen shown won't stop you from showing other screens or doing other things...it is just that while your my_key screen is being shown the keys you don't want to do anything won't do anything.
Thanks for responding! I tried that out in a new project I created just for testing, and this screen worked perfectly:

Code: Select all

screen my_keys:
    key "K_ESCAPE" action NullAction()
When I used "show screen" in the middle of some dialogue, I could still advance the dialogue but hitting escape did nothing. That's exactly the kind of thing I want. However, when I tried doing the exact same thing in my actual project, it didn't work and I have no idea why. Hitting escape still went to the menu like usual, even though I was showing the screen the same way I did in the testing project. Do you happen to have any idea what might be interfering with it working properly?
ImageImageImage

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Trying to temporarily disable some key bindings

#4 Post by trooper6 »

Are you defining K_ESCAPE anywhere else? It sounds like maybe you are putting the escape back in thus overriding your screen?
You might want to check your code. If you can't find anything, make a fresh project and and add the code back in piece by piece to see what might be breaking it.
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

User avatar
parttimestorier
Veteran
Posts: 429
Joined: Thu Feb 09, 2017 10:29 pm
Completed: No Other Medicine, Well Met By Moonlight, RE:BURN, The Light at the End of the Ocean, Take A Hike!, Wizard School Woes
Projects: Seeds of Dreams
itch: janetitor
Location: Canada
Contact:

Re: Trying to temporarily disable some key bindings

#5 Post by parttimestorier »

trooper6 wrote: Wed Aug 14, 2019 12:56 am Are you defining K_ESCAPE anywhere else? It sounds like maybe you are putting the escape back in thus overriding your screen?
You might want to check your code. If you can't find anything, make a fresh project and and add the code back in piece by piece to see what might be breaking it.
I used ctrl-F to search all my scripts for K_ESCAPE and didn't find it anywhere else unfortunately. So I guess unless there's any other way to toggle the key bindings, I will have to work on adding it all piece by piece to a new project sometime. Thanks for your help though!
ImageImageImage

Post Reply

Who is online

Users browsing this forum: AWizardWithWords, Bing [Bot]