Update 3: Improved Item Counting


Through testing, I realized that the previous version of the code could cause a small issue, which happened to come up in my own game.

It only affects setups where:

  • A choice has a condition= kwarg that fails, and
  • The total number of menu items (len(items)) is used elsewhere in your custom choice(items) screen for visuals (for example, triggering a scrollbar when there are more than 5 items).

In the old version, failed conditionals would still be counted as items, even though they weren't actually shown — which could throw off item-based calculations. 

To fix this, I added a new variable before the for loop, which is now used to loop through choices:

$ visible_items = [i for i in items if i.kwargs.get("condition", True)]
for i in visible_items:
    ...

This ensures that only visible choices are counted. There’s also no longer any need to manually skip failed choices inside the loop, so the code is now slightly cleaner and shorter overall.

This probably won’t matter for most people using the default setup, but I wanted to make sure developers working with more complex screens don't run into unexpected behavior!

If this issue comes up for you,  use len(visible_items) to make extra calculations within the screen :)

Get Choice Kwargs Tutorial For Ren’py

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.