Page 1 of 1

How to Make Textbutton Loop from Last Item to First Item in List (solved)

Posted: Tue Jul 10, 2018 5:29 pm
by noeinan
Okay, so I'm making a character creator game (dressup game style) and I have a screen that allows the player to click left or right to scroll through available character options. However! Right now, the player can go from start to finish, but when they reach the end (say item 22) they have to click the back button and go through the whole list again to get to the beginning.

I've tried searching the forums for a way to make the buttons loop back to item 01 if you click > while on the last item (22), but I don't think I have the right keywords. I'm mostly coming up with a bunch of unrelated stuff. I feel like this shouldn't be too difficult, but I've reached a bit of a block in my own search. If anyone could help me out, I'd super appreciate it! Here is my code:

Code: Select all

init python:
    base, hips, waist, arms, chest, face, mouth, nose, eyes, brows, ears = 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 # default dressup items
    base_styles_num, hips_styles_num, waist_styles_num, arms_styles_num, chest_styles_num, face_styles_num, mouth_styles_num, nose_styles_num, eyes_styles_num, brows_styles_num, ears_styles_num = 4, 3, 3, 4, 12, 12, 12, 12, 12, 12, 22 # number of styles for each dressup item

Code: Select all

    frame:
        xalign 1.0
        xsize 1407
        yfill True

        hbox:

            xalign 0.05
            yalign 0.05
            spacing 25

            textbutton _("<") action SetVariable('base', max(base-1,0))
            text "Base"
            textbutton _(">") action SetVariable('base',min(base+1,base_styles_num))

Re: How to Make Textbutton Loop from Last Item to First Item in List

Posted: Tue Jul 10, 2018 5:58 pm
by Remix
SetVariable( 'base', base-1 if base > 0 else base_styles_num )

SetVariable( 'base', base+1 if base < base_styles_num else 1 )

Might need to wrap the condition in parenthesis though... Ren'Py should calculate it using python
SetVariable( 'base', ( base+1 if base < base_styles_num else 1 ) )

Re: How to Make Textbutton Loop from Last Item to First Item in List (solved)

Posted: Tue Jul 10, 2018 6:41 pm
by noeinan
That worked (the bottom one with extra parentheses), I just had to use 1 instead of 0 or else it would add an extra blank image. Here's the code I ended up with:

Code: Select all

        hbox:

            xalign 0.05
            yalign 0.05
            spacing 25

            textbutton _("<") action SetVariable( 'base', ( base-1 if base > 1 else base_styles_num ) )
            text "Base [base] / [base_styles_num]"
            textbutton _(">") action SetVariable( 'base', ( base+1 if base < base_styles_num else 1 ) )
Thank you very much!