Using iteration with gallery unlock conditions

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
GODANU
Newbie
Posts: 3
Joined: Tue Jun 06, 2023 4:20 am
Discord: 591#1056
Contact:

Using iteration with gallery unlock conditions

#1 Post by GODANU »

Code: Select all

 init python :
    cg_lists = [0,0]
    gallery_cg_items = [
        ["images/cg/mina1.png"], ["images/cg/mina2.png"]
    ]
    gallery_unlock_items = [
        ["images/cg/small_mina1.png"], ["images/cg/small_mina2.png"]
    ]
    gal_rows = 2 
    gal_cols = 3 
    thumbnail_x = 420 
    thumbnail_y = 250 
    cg_page = 0 
    cg_idx = 0 
    gal_cells = gal_rows * gal_cols
    g_cg = Gallery() 
    g_cg.locked_button = "images/cg/black.png"
    g_cg.always_unlocked = False
    while cg_idx < len(cg_lists) :
        g_cg.button("cg_list" + str(cg_idx)) 
        g_cg.image(gallery_cg_items[cg_idx]) 
        g_cg.condition("cg_lists[cg_idx] == 1") 
        cg_idx += 1
    cg_idx = 0
    g_cg.transition = dissolve 
Here is the iteration part to reduce the length of code

giving condition to each images.

Code: Select all

while cg_idx < len(cg_lists) :
    g_cg.button("cg_list" + str(cg_idx))  
    g_cg.image(gallery_cg_items[cg_idx]) 
    g_cg.condition("cg_lists[cg_idx] == 1") 
    cg_idx += 1
What I intended to do is
cg_idx == 0

if cg_lists[0] == 1 then g_cg.condition(True), unlock the first image

cg_idx += 1

if cg_lists[1] == 0 then g_cg.condition(False), leave the second image locked

...
but what happened is
cg_idx == 0

cg_lists[0] == 1 so it is "True"

cg_idx += 1

cg_lists[1] == 0 so it is "False"

g_cg.condition(True and False) so that both image locked

Idk why Renpy considers all conditions in the while loop as a "one condition merged by an AND gate".

I tried for loop but has the same result...

Using g_cg.unlock or g_cg.unlock_image is not what I want,

because I want to make player be able to unlock CGs even if he/she "didn't see that CG" ex) Hidden CG etc.

Could you help me?

Appreciate.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Using iteration with gallery unlock conditions

#2 Post by enaielei »

You're not interpolating the cg_idx variable in the string expression for the condition. Do...

Code: Select all

g_cg.condition("cg_lists[{}] == 1".format(cg_idx)) 

GODANU
Newbie
Posts: 3
Joined: Tue Jun 06, 2023 4:20 am
Discord: 591#1056
Contact:

Re: Using iteration with gallery unlock conditions

#3 Post by GODANU »

enaielei wrote: Fri Jun 16, 2023 6:20 am You're not interpolating the cg_idx variable in the string expression for the condition. Do...

Code: Select all

g_cg.condition("cg_lists[{}] == 1".format(cg_idx)) 
It works! Thank you for great advice :)

Post Reply

Who is online

Users browsing this forum: Ocelot