Insensitive menu options still selectable with keyboard

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
minyan
Miko-Class Veteran
Posts: 630
Joined: Tue Feb 10, 2015 3:59 pm
Completed: Trial By Fire, Heartbaked, Ellaria, Plain, This My Soul, The Pretenders Guild
Projects: Arena Circus
Tumblr: minyanstudios
itch: harlevin
Contact:

Insensitive menu options still selectable with keyboard

#1 Post by minyan »

Hello,

I'm using this code so that users can select menu choices with the number keys:

Code: Select all

for n, i in enumerate(items, 1): # n would be the number starting from 1
            if n<10:
                key str(n) action i.action

            textbutton str(n) + ". " + i.caption action i.action style "nvl_button"
It works fine, and the choices are displayed like:

1. Choice 1
2. Choice 2

Users can choose by pressing 1 or 2 on the keyboard.

However, if an option is insensitive, for example:

menu:
"choice 1" if stat > 0:
pass
"choice 2":
pass

In the case that the variable "stat" was at 0, they will be able to see that menu option, but they can't choose it. With my code above, they can't click on it, but if they press 1 on the keyboard, it still lets them choose that option. Is there anyway to disable keyboard input for insensitive choices?
ImageImage

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Insensitive menu options still selectable with keyboard

#2 Post by hell_oh_world »

a button has a keysym property, use that instead...
https://www.renpy.org/doc/html/screens.html#textbutton

User avatar
minyan
Miko-Class Veteran
Posts: 630
Joined: Tue Feb 10, 2015 3:59 pm
Completed: Trial By Fire, Heartbaked, Ellaria, Plain, This My Soul, The Pretenders Guild
Projects: Arena Circus
Tumblr: minyanstudios
itch: harlevin
Contact:

Re: Insensitive menu options still selectable with keyboard

#3 Post by minyan »

I’m sorry, I’m not familiar enough with that property to know how I’d change the code. Can you explain a little more?
ImageImage

User avatar
minyan
Miko-Class Veteran
Posts: 630
Joined: Tue Feb 10, 2015 3:59 pm
Completed: Trial By Fire, Heartbaked, Ellaria, Plain, This My Soul, The Pretenders Guild
Projects: Arena Circus
Tumblr: minyanstudios
itch: harlevin
Contact:

Re: Insensitive menu options still selectable with keyboard

#4 Post by minyan »

hell_oh_world wrote: Fri Jul 16, 2021 12:25 am a button has a keysym property, use that instead...
https://www.renpy.org/doc/html/screens.html#textbutton

I’m sorry, I’m not familiar enough with that property to know how I’d change the code. Can you explain a little more?
ImageImage

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Insensitive menu options still selectable with keyboard

#5 Post by hell_oh_world »

Code: Select all

for n, i in enumerate(items, 1): # n would be the number starting from 1
            textbutton str(n) + ". " + i.caption:
              action i.action
              style "nvl_button"
              keysym (str(n) if n < 10 else None) # works like the `key` displayable on screens...
            

User avatar
vollschauer
Veteran
Posts: 231
Joined: Sun Oct 11, 2015 9:38 am
Github: vollschauer
Contact:

Re: Insensitive menu options still selectable with keyboard

#6 Post by vollschauer »

remove that:

Code: Select all

key str(n) action i.action
add keysym to the textbutton, I think it is something like that .... you'll find out

Code: Select all

textbutton str(n) + ". " + i.caption action i.action keysym str(n) style "nvl_button"

User avatar
minyan
Miko-Class Veteran
Posts: 630
Joined: Tue Feb 10, 2015 3:59 pm
Completed: Trial By Fire, Heartbaked, Ellaria, Plain, This My Soul, The Pretenders Guild
Projects: Arena Circus
Tumblr: minyanstudios
itch: harlevin
Contact:

Re: Insensitive menu options still selectable with keyboard

#7 Post by minyan »

hell_oh_world wrote: Fri Jul 16, 2021 12:14 pm

Code: Select all

for n, i in enumerate(items, 1): # n would be the number starting from 1
            textbutton str(n) + ". " + i.caption:
              action i.action
              style "nvl_button"
              keysym (str(n) if n < 10 else None) # works like the `key` displayable on screens...
            
Thank you, this worked!
ImageImage

User avatar
minyan
Miko-Class Veteran
Posts: 630
Joined: Tue Feb 10, 2015 3:59 pm
Completed: Trial By Fire, Heartbaked, Ellaria, Plain, This My Soul, The Pretenders Guild
Projects: Arena Circus
Tumblr: minyanstudios
itch: harlevin
Contact:

Re: Insensitive menu options still selectable with keyboard

#8 Post by minyan »

vollschauer wrote: Fri Jul 16, 2021 12:27 pm remove that:

Code: Select all

key str(n) action i.action
add keysym to the textbutton, I think it is something like that .... you'll find out

Code: Select all

textbutton str(n) + ". " + i.caption action i.action keysym str(n) style "nvl_button"
Thank you!
ImageImage

Post Reply

Who is online

Users browsing this forum: Bing [Bot], half1-2moon, Majestic-12 [Bot]