[SOLVED]Grid Code for Textbuttons Works in RenPy 7.4.11 but not in RenPy 8.0

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
LateWhiteRabbit
Eileen-Class Veteran
Posts: 1867
Joined: Sat Jan 19, 2008 2:47 pm
Projects: The Space Between
Contact:

[SOLVED]Grid Code for Textbuttons Works in RenPy 7.4.11 but not in RenPy 8.0

#1 Post by LateWhiteRabbit »

Okay, so I could probably just stick with Ren'Py 7.4.11 for my game, but I'm not far along in developing it and I'd really like to be using Ren'Py 8.

I have custom code that takes Menu choices in the script and presents them to the players as a grid of text buttons. The code works perfectly in Ren'Py 7.4.11, and does exactly what I want it to. If there are only 2 choices, it shows 2 buttons. If there are 6 choices, it shows 6 buttons. If there are more than 6 buttons, it displays a message for the player to scroll down for more choices. Perfect.

Code: Select all

screen choice(items):
    style_prefix "choice"

    frame:
        background None
        xalign 0.5
        ypos 1089
        vpgrid id "cgrid":
            cols 3
            xspacing 0
            yspacing 42
            draggable True
            mousewheel True
            ysize 238

            # Creates a custom caption system for menu choices, allowing additional feedback
            # to the player. Results are displayed in the screen 'descriptions'.
            $ choice_count = 0
            for i in items:
                $ tt = i.caption[i.caption.find("(")+1:i.caption.find(")")]
                $ ti = i.caption[i.caption.find("<")+1:i.caption.find(">")]
                $ caption = i.caption.replace(" ("+tt+")", "").replace(" <"+ti+">", "")
                $ choice_count += 1

                textbutton caption:
                    background "gui/choice_idle.webp"
                    hover_background "gui/choice_hover.webp"
                    hovered [SetVariable("choice_description", tt), SetVariable("talent_indicator", ti)]
                    unhovered [SetVariable("choice_description", ""), SetVariable("talent_indicator", "")]
                    action [i.action, SetVariable("choice_description", ""), SetVariable("talent_indicator", "")]
    if choice_count > 6:
        text "{font=fonts/Montserrat-Medium.otf}{size=35}{color=#c75e73}▼ {/color}{color=#e9e2cf}Scroll Down for More Choices{/color}{color=#c75e73} ▼{/color}{/size}{/font}":
            ypos 1370
            xpos 1277
            xalign 0.5
            yalign 0.5
No errors in Ren'Py 7.4.11 as I said. Works like I want, every time.

In Ren'Py 8.0.0.22061101, I get a crash.
Exception: VPGrid not completely full, needs a multiple of 3 children.
Now, conceptually, I can see what is wrong. The menu that is causing this crash only has 2 choices, so 2 text buttons to generate, and because the VPGrid in my code has 3 columns, Ren'Py has decided to freak out because the grid isn't full - hence the "needs a multiple of 3 children".

The problem is I don't know how to make Ren'Py 8 happy with my code, since by the nature of what I'm doing, I don't want to have to always present menu choices in multiples of 3. So what is it I'm doing wrong, and why does my code work in 7.4.11 but not in 8.0?

EDIT: The answer, for anyone else experiencing this, is to add:

Code: Select all

define config.allow_underfull_grids = True
Special thanks to Syrale for the quick solution.
Last edited by LateWhiteRabbit on Sun Jun 12, 2022 2:28 pm, edited 2 times in total.

User avatar
Syrale
Regular
Posts: 101
Joined: Sun Oct 25, 2015 10:28 am
Completed: Robot Daycare, Deep Sea Valentine, Locke(d)
Projects: Artificial Selection, Artificial Fashionista, rei_carnation
Github: kigyo
itch: kigyo
Discord: kigyodev
Contact:

Re: Grid Code for Textbuttons Works in RenPy 7.4.11 but not in RenPy 8.0

#2 Post by Syrale »

It's possible that this could be fixed just by adding:

Code: Select all

define config.allow_underfull_grids = True
ImageArtificial Selection (ongoing) |ImageDeep Sea Valentine | ImageRobot Daycare (NaNo19)
| ImageArtificial Fashionista (NaNo24)

My Developer Tools: Ren'Py Minimap/Location System | Ren'Py Word Counter+

User avatar
LateWhiteRabbit
Eileen-Class Veteran
Posts: 1867
Joined: Sat Jan 19, 2008 2:47 pm
Projects: The Space Between
Contact:

Re: Grid Code for Textbuttons Works in RenPy 7.4.11 but not in RenPy 8.0

#3 Post by LateWhiteRabbit »

Syrale wrote: Sun Jun 12, 2022 1:57 pm It's possible that this could be fixed just by adding:

Code: Select all

define config.allow_underfull_grids = True
Wow.

Yep. That fixed it. No other code changes necessary. Thanks a lot! That was fast!

For my curiosity and education, do you or anyone else know why this is necessary in 8, but not 7.4.11?
Last edited by LateWhiteRabbit on Sun Jun 12, 2022 2:26 pm, edited 1 time in total.

User avatar
Syrale
Regular
Posts: 101
Joined: Sun Oct 25, 2015 10:28 am
Completed: Robot Daycare, Deep Sea Valentine, Locke(d)
Projects: Artificial Selection, Artificial Fashionista, rei_carnation
Github: kigyo
itch: kigyo
Discord: kigyodev
Contact:

Re: Grid Code for Textbuttons Works in RenPy 7.4.11 but not in RenPy 8.0

#4 Post by Syrale »

I have no idea, to be honest. I'm pretty sure I've gotten underfull grid errors before, so I'm more surprised that your code was working in 7.4.11!
ImageArtificial Selection (ongoing) |ImageDeep Sea Valentine | ImageRobot Daycare (NaNo19)
| ImageArtificial Fashionista (NaNo24)

My Developer Tools: Ren'Py Minimap/Location System | Ren'Py Word Counter+

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: [SOLVED]Grid Code for Textbuttons Works in RenPy 7.4.11 but not in RenPy 8.0

#5 Post by PyTom »

This is just reporting an error in the game. You said the grid would be three columns wide, but it's only two columns full. That's an error, and so Ren'Py is now reporting that error. (This is only produced in developer mode, not in released games.)

You can pad the grid out with:

Code: Select all

if choice_count % 3 == 1:
    null
    null
elif choice_count %3 == 2:
    null
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Lacha, Majestic-12 [Bot]