[solved] automatic vpgrid "null" padding - is there a better way

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
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

[solved] automatic vpgrid "null" padding - is there a better way

#1 Post by Imperf3kt »

I have a grid of buttons which I make using a for loop. Over time, I add objects to a list, and that gets added to the grid. This usually causes a grid not full exception, so to avoid that I check if the length of the list and add an appropriate number of null statements, but it feels really clunky and there's probably a better way.

Code: Select all

screen achievements():


    tag menu

    use game_menu(_("Achievements"), scroll="viewport"):

        style_prefix "achievements_screen"

        vpgrid:
            cols 6
            spacing 88
            draggable False
            mousewheel True
            scrollbars None
            xalign 0.5
            yalign 0.0

            for a in ach_list:
                imagebutton:
                    alt a.name
                    idle a.pic
                    hover_foreground Text(_(a.name), xalign=0.5, yalign=1.0, size=22)
                    idle_foreground Text(_(a.name), xalign=0.5, yalign=1.0, size=22)
                    action Show("achievement", PushMove(0.2, mode="pushup"), achieve=a.name, achieve_cosmetic=a.cosmetic, achieve_secret=a.secret, achieve_obtain=a.obtain, achieve_type=a.type)
                    focus_mask True
                    tooltip _(a.name)

            ## Grid padding ##
            if len(ach_list) % 6 == 1:
                null
                null
                null
                null
                null

            if len(ach_list) % 6 == 2:
                null
                null
                null
                null

            if len(ach_list) % 6 == 3:
                null
                null
                null

            if len(ach_list) % 6 == 4:
                null
                null

            if len(ach_list) % 6 == 5:
                null

I'm hoping to be able to remove the section below ## grid padding ## entirely if possible
Last edited by Imperf3kt on Wed Jun 22, 2022 7:41 am, edited 1 time in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Zetsubou
Miko-Class Veteran
Posts: 522
Joined: Wed Mar 05, 2014 1:00 am
Completed: See my signature
Github: koroshiya
itch: zetsuboushita
Contact:

Re: automatic vpgrid "null" padding - is there a better way

#2 Post by Zetsubou »

Using Renpy 7.5/8 you should be able to use the new config "allow_underfull_grids":
https://www.renpy.org/dev-doc/html/conf ... full_grids

For 7.4 and below you could use a loop instead of your mod statements. Still not ideal, but at least it's shorter.
Something like

Code: Select all

howManyNulls = 5 - (len(ach_list) % 6)
for i in range(howManyNulls):
    null
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too, Sable's Grimoire, My Heart Grows Fonder, Man And Elf, A Dragon's Treasure, An Adventurer's Gallantry
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers, Wolf Tails

Working on:
Sable's Grimoire 2

https://zetsubou.games

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: automatic vpgrid "null" padding - is there a better way

#3 Post by Imperf3kt »

Thanks. I knew 7.5 had introduced something, but couldn't remember what it was.

Also thanks for the loop suggestion, thats much tidier too.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: [solved] automatic vpgrid "null" padding - is there a better way

#4 Post by zmook »

It's new in 7.5/8.0, and the changelog mentions that there's also a grid property

Code: Select all

    allow_underfull True
for if you want to specify per grid.

https://www.renpy.org/dev-doc/html/chan ... nd-vpgrids
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot