[SOLVED]List of CheckBox And ToggleVariable

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
GoldenD
Regular
Posts: 43
Joined: Thu Jan 16, 2020 2:01 am
Contact:

[SOLVED]List of CheckBox And ToggleVariable

#1 Post by GoldenD »

Hi guys,
i would a list of checkbox which depends of a list of items.
And for toggle each button, i have a list of true/false values matching with list of items. Look at :

Code: Select all

default listSelect  = [False, False, False, False, False, False, False, False, False, False, False, False, False]
#i tried with listSelect = [] it's the same
.../...
screen displayItems(listOfItems):
    for _var in listOfItems:
        textbutton _var.name xpos 200 ypos 200:
            action ToggleVariable("listSelect[listOfItems.index[_var]]")
But renpy says : The variable [listSelect[_var]] does not exist

Is there a solution ?
Last edited by GoldenD on Mon Mar 02, 2020 12:56 am, edited 1 time in total.

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: List of CheckBox And ToggleVariable

#2 Post by Remix »

You likely want to iterate the index value... zero to length of list minus one.
Then the ToggleDict action should be good.
Might want to rename your variable too (mixed case and especially CamelCase in Python imply a Class)

Code: Select all

    vbox:
        for idx in range(len(list_select)):
            textbutton "Item [idx]":
                action ToggleDict( list_select, idx, True, False )
Frameworks & Scriptlets:

GoldenD
Regular
Posts: 43
Joined: Thu Jan 16, 2020 2:01 am
Contact:

Re: List of CheckBox And ToggleVariable

#3 Post by GoldenD »

Ok,
i'll try but as you maybe not noticed, the list i loop isn't list_select but a list of items. list_select is a second list used to flag toggle state (is clear ?)

But maybe your answer can help me to find the soultion.
I'll be back !

GoldenD
Regular
Posts: 43
Joined: Thu Jan 16, 2020 2:01 am
Contact:

Re: List of CheckBox And ToggleVariable

#4 Post by GoldenD »

Remix wrote: Sun Mar 01, 2020 7:08 am You likely want to iterate the index value... zero to length of list minus one.
Then the ToggleDict action should be good.
Might want to rename your variable too (mixed case and especially CamelCase in Python imply a Class)

Code: Select all

    vbox:
        for idx in range(len(list_select)):
            textbutton "Item [idx]":
                action ToggleDict( list_select, idx, True, False )
Ok, I did tests and it's well but not exactly what I hope. The first sample bottom is ok but list_select is fixed. The second, I would, dynamically assign values in list_select but no reaction when I click on buttons.
Common Code

Code: Select all

style checkbox_button:
    xysize (100, 100)
    background Solid("#ffff00")                 	# YELLOW    UNCHECKED
    hover_background Solid("#ffffff")           	# WHITE     UNCHECKED HOVERED
    selected_idle_background Solid("#00ff00")   	# GREEN     CHECKED
    selected_hover_background Solid("#6d0002")  	# RED       CHECKED HOVERED

label start:
    call screen test
        
First sample ok

Code: Select all

default list_select  = {0:False,1:False,2:False,3:False}
    
screen test():
    $ x_pos = 300
    for idx in range(len(list_select)):
        textbutton "Item [idx]"  xpos x_pos:
            action ToggleDict( list_select, idx, True, False )
            style "checkbox_button"
        $x_pos +=100
Second sample doesn'twork

Code: Select all

default list_select  = dict()

screen test():
    $ x_pos = 300

    for idx in range (4):
        $ list_select[idx] = True

    for idx in range(len(list_select)):
        textbutton "Item [idx]"  xpos x_pos:
            action ToggleDict( list_select, idx, True, False )
            style "checkbox_button"
        $x_pos +=100
And I don't understand why ?

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: List of CheckBox And ToggleVariable

#5 Post by Remix »

Because your screen rebuilds the list as all True and when you click any button the screen is redrawn, which rebuilds the list...
Frameworks & Scriptlets:

GoldenD
Regular
Posts: 43
Joined: Thu Jan 16, 2020 2:01 am
Contact:

Re: List of CheckBox And ToggleVariable

#6 Post by GoldenD »

Remix wrote: Sun Mar 01, 2020 5:39 pm Because your screen rebuilds the list as all True and when you click any button the screen is redrawn, which rebuilds the list...
Great Thanks Remix,
I can fix that.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]