Ren’Py Code Snippets I: Press 1 for best choice 2

EDIT: Fixed to be more to the point, haha. Thanks, renpytom, you are best dev. <3

Blazingly simple, changes Ren’Py’s default choice menu to respond to 123… keys, a la Infinity Engine games. We use the iterating (for action in items) the choice already does and assign it a number, and that number becomes the key mapping:

tl;dr: 1 is always best option, press 1 to win.

As I work more on my stuff, I’ll be posting more code and that has some practical use (read: and is not a total hackjob). Disclaimer being, while I try to avoid Unintentional Consequences, I haven’t tested these enough to 100% guarantee this isn’t going to cause random problems with other Ren’Py engine stuff down the line.

2 thoughts on “Ren’Py Code Snippets I: Press 1 for best choice

  1. Reply Noc Mar 5,2014 1:45 AM

    That’s cool and nicely implemented, but you might want to add an “if assignKey < 10" before "$ assignKey = (assignKey + 1)" in case of menus with many choices.

    Also, you can do something like this:

    text (str(assignKey) + ". " + caption) style "menu_choice"

    …instead of:

    text caption style "menu_choice

    …to show which key corresponds to each choice.

    • Reply Quattro Mar 5,2014 5:30 AM

      You’re very right about the 10+ thing, I did punch that in with the expectation that nobody would ever make a choice with more than 9 options and there would be no reason to put in a failsafe, but that was a bit naive of me.

      I’ve updated it so doesn’t attempt to do things with the mystical 10 key.

Leave a Reply