Ren'Py Remove an element of a list using screen action.

Milvidi

Member
Game Developer
Feb 26, 2018
200
498
So I have a card class, and a list that contains 5 cards, like so:

Code:
card = []
card.append(Card("card1, image=card1.png"))
...
...
card.append(Card("card5, image=card5.png"))
Then in the screen:

Code:
hbox:
    for q in card:
        $ cardImg = q.image
        imagebutton:
            idle cardImg
            hover cardImg
            action Call("Play_Card")
What I want to do here is, once I click a card, it gets removed from the card list, and disappearing from the screen. This is my current solution:

Code:
hbox:
    for q in card:
        $ cardImg = q.image
        imagebutton:
            idle cardImg
            hover cardImg
            action SetVariable("cardToDiscard", card.index(q)), Call("Play_Card")
Then in the Play_Card label:

Code:
label Play_Card:
    python:
        card.remove(card[cardToDiscard])
It works, but is there any other way to do it right in the button? Something similar to RemoveFromSet? Or just a shorter way to do it.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,286
It works, but is there any other way to do it right in the button? Something similar to RemoveFromSet? Or just a shorter way to do it.
RemoveFromSet, as well as AddToSet, also apply to list.