for loop and lists

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
Saiffyros
Newbie
Posts: 15
Joined: Sun May 21, 2017 10:13 pm
Contact:

for loop and lists

#1 Post by Saiffyros » Tue Feb 13, 2018 7:09 pm

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.

irredeemable
Regular
Posts: 78
Joined: Thu Feb 08, 2018 7:57 am
Contact:

Re: for loop and lists

#2 Post by irredeemable » Tue Feb 13, 2018 7:23 pm

Code: Select all

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

Code: Select all

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

Saiffyros
Newbie
Posts: 15
Joined: Sun May 21, 2017 10:13 pm
Contact:

Re: for loop and lists

#3 Post by Saiffyros » Tue Feb 13, 2018 7:28 pm

That works perfectly. Thanks :-)

Post Reply

Who is online

Users browsing this forum: No registered users