It is currently 06 Sep 2025, 21:23
   
Text Size

Card isInZone function

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Card isInZone function

Postby Sloth » 06 Aug 2013, 14:26

The isInZone function in the card class is not really doing what it's supposed to do.

It's used a lot to test whether a card is still on the battlefield (or in a nother zone). When a card object is outdated (like the source of an ability or trigger waiting on the stack) it will still pretend to be in the previous zone even though the current card has benn destroyed or otherwise changed zone.

When i search for "isInPlay()" in our code i get 73 results and nearly all of them do not function properly with this isInZone function.

@Max: What was the reason to change the isInZone function (r22432)?

For reference, here is the old version:

Code: Select all
    public boolean isInZone(final ZoneType zone) {
        return getGame().isCardInZone(this, zone);
    }
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Card isInZone function

Postby Max mtg » 07 Aug 2013, 09:24

Sloth wrote: When a card object is outdated (like the source of an ability or trigger waiting on the stack) it will still pretend to be in the previous zone even though the current card has benn destroyed or otherwise changed zone.
Then it's the problem in code that does not update the Card instance with new zone.

It is the card that may belong to one and only zone (or none at all). Lists of cards present an opportunity to hold a single card in several zones at once, that is nonsense.

There are also some code routines that iterate over cardlist and need to know the zone each card belongs to. Using the previous implementation would lead to quadruple loop (1st loop is over card list, 2nd one is over players, 3rd over zones of current player and 4th is the lookup inside zone for a certain card)
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Card isInZone function

Postby Sloth » 07 Aug 2013, 11:09

Max mtg wrote:
Sloth wrote: When a card object is outdated (like the source of an ability or trigger waiting on the stack) it will still pretend to be in the previous zone even though the current card has benn destroyed or otherwise changed zone.
Then it's the problem in code that does not update the Card instance with new zone.
The problem is that a card moving from the battlefield to any other zone will create a new card object and the old card object (lingering around as source of a spell/ability or triggering object) will have the wrong currentZone variable.

r22822 fixes most of the issues, but there is still the corner case that a card can change zones multiple times while something on the stack refers to it.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 70 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 70 users online :: 0 registered, 0 hidden and 70 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 70 guests

Login Form