Ren'Py Dynamically changing variables in screen

noping123

Well-Known Member
Game Developer
Jun 24, 2021
1,717
2,723
I'm pretty sure my title doesn't even come CLOSE to accurately describing what I'm trying to do, but honestly I struggled to describe it properly in 10 words or less.

So here's the important bit of screen code

Code:
        if persnum == 0:
            imagebutton:
                idle "wallpapernone"
                pos 900,350
                action NullAction()
            textbutton "Set Wallpaper":
                style "quick_button"
                pos 925,650
                action SetVariable("phonebg","bgoff"), SelectedIf(credits==11919123129)
        elif not persistent.wallpaperbought_list[persnum]:
            imagebutton:
                idle "notbought"
                pos 900,350
                action NullAction()
        elif persistent.wallpaperbought_list[persnum]:
            imagebutton:
                idle "wallpaper" + str(persnum) + "ico"
                pos 900,350
                action Show('imagescrn',img="images/phone/wallpapers/wallpaper[persnum].webp")
            textbutton "Set Wallpaper":
                style "quick_button"
                pos 925,650
                action SetVariable("phonebgnum",persnum),SetVariable("phonebg","bgon"), SelectedIf(credits==11919123129)

    hbox:
        spacing 20
        xpos 830
        ypos 750
        if persnum > 0:
            textbutton "Prev. Page":
                style "quick_button"
                action SetVariable('persnum',persnum - 1), SelectedIf(credits==11919123129)
        else:
            fixed:
                xysize 150,130
        if persnum < 10:
            textbutton "Next Page":
                style "quick_button"
                action SetVariable('persnum',persnum + 1), SelectedIf(credits==11919123129)

It works correctly (with one caveat). You can purchase the wallpapers in a separate store screen. If purchased, they show up here and you can assign them. If not purchased, it displays a "Not purchased" image, and the first option (persnum = 0), allows you to set the default (blank) image instead.

All of it works correctly - HOWEVER. What I haven't yet been able to figure out is this:
Currently, hitting next page cycles through the images, displaying a "Not purchased" image for any that haven't been bought yet. What I'd like it to do is just skip it entirely - so for example, if wallpaperbought_list[3],[5],[7] are bought, and all the rest aren't, I'd like it to cycle through those 3 via next/previous page, and not even trigger "not purchased" for 1,2,4,6,8,9,10.

Getting the top part of the display (the part where it actually displays the image) to do that is easy, the problem I'm running into is figuring out how to get the next/previous buttons to function that way.

In other words, in the above scenario (3,5,7 bought only), you open the screen at 0 (the default image). Hitting next, I'd like it to jump directly to 3, next again directly to 5, etc - this way I could skip the "not purchased" bit entirely.

Atm the only way I've come up with to accomplish that is terrible (basically a ton of if/elif/else statements, for each condition), and I'd rather keep it as is than do that.
 

gojira667

Member
Sep 9, 2019
325
320
This is for already purchased wallpapers and persistent.wallpaperbought_list is a list of bought wallpaper referenced by index of True/False?

Code:
    default wallpaper_i = 0
    default bought_wallpaper = [0,] + [i for i,wpb enumerate(persistent.wallpaperbought_list) if wpb = True)]
Then have the Next/Prev buttons cycle through bought_wallpaper screen var (ids 0 plus any purchased), inc/dec wallpaper_i and set persnum to bought_wallpaper[wallpaper_i].

Actually you may want it as a function. Main point is to have a list of only valid ids that you cycle through.
 
  • Like
Reactions: anne O'nymous

noping123

Well-Known Member
Game Developer
Jun 24, 2021
1,717
2,723
This is for already purchased wallpapers and persistent.wallpaperbought_list is a list of bought wallpaper referenced by index of True/False?

Code:
    default wallpaper_i = 0
    default bought_wallpaper = [0,] + [i for i,wpb enumerate(persistent.wallpaperbought_list) if wpb = True)]
Then have the Next/Prev buttons cycle through bought_wallpaper screen var (ids 0 plus any purchased), inc/dec wallpaper_i and set persnum to bought_wallpaper[wallpaper_i].

Actually you may want it as a function. Main point is to have a list of only valid ids that you cycle through.

The way I ended up doing it is hacky and probably not good, but it works.

What I did was I have my initial list, of T/F values.
I then have a second list, which is JUST numbers - to match the length of the first list. (so the 2nd list is 0,1,2,3,4,5...etc)

I THEN had a new variable $pageselector = list(compress(2ndlist,persistent.wallpaperbought_list))

That set pageselector to a list of numbers, which was just the true values. (So if 1,3,5,7,9 were true, then pageselector = [1,3,5,7,9]

Then the prev/next buttons are just coded to only cycle through values that exist in the pageselector variable, and ignore everything else.

It took some janky code to get it working, but it works. It's actually pretty similar to what you did, looking at it, the main difference is, whenever I update the game with new wallpapers, I now have to update both the actual list with the T/F values, as well as the reference list, with numbers - which honestly isn't a big deal. I just .append every time I add new stuff.

I havent gotten there yet, but I plan on just doing something like this:

Code:
if len(persistent.wallpaperbought_list) < 15:
    persistent.wallpaperbought_list.append(False)
    2nd_list_Idont_remember_thename_of_right_now.append(10)
and so on. The way it's written right now, just that should allow it to continue to function without any extra work.