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

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
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

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

#1 Post 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))
Last edited by noeinan on Tue Jul 10, 2018 6:41 pm, edited 1 time in total.
Image

Image
Image

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

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

#2 Post 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 ) )
Frameworks & Scriptlets:

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

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

#3 Post 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!
Image

Image
Image

Post Reply

Who is online

Users browsing this forum: bonnie_641, konimyun