Page 1 of 1

for loop and lists

Posted: Tue Feb 13, 2018 7:09 pm
by Saiffyros
I'm using the following code to create imagebuttons:

Code: Select all

screen test1:
    grid 5 1:
        xalign 0.7
        yalign 0.9
        spacing 20
        for i in deck:
            imagebutton idle i.picture:
                hover i.picture2
                action allies.append(i), Return("fight")
        for i in range (len(deck), 5):
            text Null()
It includes all the objects from the list deck to the list allies....
I wanted to include just the object that was clicked by the user.

So it generates 5 buttons and I wanted to include in the list allies, just the one that was clicked.

Not sure how I'd do that.

Re: for loop and lists

Posted: Tue Feb 13, 2018 7:23 pm
by irredeemable

Code: Select all

action allies.append(i), Return("fight")
should be

Code: Select all

action AddToSet(allies, i), Return("fight")

Re: for loop and lists

Posted: Tue Feb 13, 2018 7:28 pm
by Saiffyros
That works perfectly. Thanks :-)