'Modelling card game zones using arrays: how to check what zone an object is in?

I've been building a little card game with a friend. We used ds_lists for building the hand, deck, play zone and discard, moving the card objects back and forth between them. One part we've struggled with was checking what zone a card is in. For example: You can see both your hand and the discard at all times but only cards in hand should be playable, i.e. move when dragged into play.

Since the objects don't know what list they're in, we've been manually updating a list of booleans inDeck, inHand, inPlay etc. then nesting the tap event logic in an if block.

Create Event:

var inDeck = false;
var inHand = false;
var inPlay = false;
var inDiscard = false

if (ds_list_find_index(Hand, card) >= 0)
{
    inHand = true
}
else if (ds_list_find_index(Play, this_card) >= 0)
{
    inPlay = true
}
Repeat for each zone

Tap event:

if (inHand)
{
     playCard();
}
if (inPlay)
{
     useCard();
}

Is this the best we can do or is there a different approach we could/should take?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source