Ren'Py [SOLVED]A function to dynamically add textbutton on a screen ?

GoldenD

Member
Sep 30, 2018
102
70
Hi,
i've the following repetitive code in a screen :
Python:
screen ui:

    zorder 105

# BACKPACK
    $ _var  = 0
    $ _xpos = 95
    $ _ypos = 55

    for _var in Hero.items:

        # THE CODE HERE
        textbutton findItemName(listOfItems, _var)    xpos _xpos ypos _ypos:
            action NullAction()
            hovered ShowTransient("the_img", msg =findItemDescription(listOfItems , _var))
            unhovered Hide("the_img")
            tooltip findItemDescription(listOfItems, _var)
            style "ui_button"

# SPELLS
    $ _var  = 0
    $ _xpos = 95
    $ _ypos = 315

    for _var in Hero.spells:

        # AND HERE
        textbutton findItemName(listOfSpells, _var) xpos _xpos ypos _ypos:
            action NullAction()
            hovered ShowTransient("the_img", msg =findItemDescription(listOfSpells , _var))
            unhovered Hide("the_img")
            tooltip findItemDescription(listOfSpells, _var)
            style "ui_button"
And there others loop with the same code (except variables of course)
Is there a way to optimize and to do a "function" that centralize the part with textbutton ?
If you have a link to the doc, i take of course.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,355
15,268
Not a function, but a screen language statement, :

Code:
screen ui:

    zorder 105

# BACKPACK
    $ _var  = 0
    $ _xpos = 95
    $ _ypos = 55

    use tbLoop( Hero.items, listOfItems)

# SPELLS
    $ _var  = 0
    $ _xpos = 95
    $ _ypos = 315

    use tbLoop( Hero.spells, listOfSpells )


screen tbLoop( iterList, listOf ):

    for _var in iterList:

        # THE CODE HERE
        textbutton findItemName(listOf, _var)    xpos _xpos ypos _ypos:
            action NullAction()
            hovered ShowTransient("the_img", msg =findItemDescription(listOf , _var))
            unhovered Hide("the_img")
            tooltip findItemDescription(listOf, _var)
            style "ui_button"
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,667
23,782
the main problem persists, all buttons of a section are placed at the same spot.
they have to be children of an auto-position container, be it a box or a grid, or their positional data also have to be modified via enumerate * offset.
 

GoldenD

Member
Sep 30, 2018
102
70
the main problem persists, all buttons of a section are placed at the same spot.
they have to be children of an auto-position container, be it a box or a grid, or their positional data also have to be modified via enumerate * offset.
Perfect, as usually. And don't worry for now, no problem for the placement.
Great Thanks.