Tonight I added a subflow to my Marvel Snap clone that will add a card to a deck. It takes 2 inputs – the card definition and the player deck record. I have three records involved in this – The Player Deck (contains fields for user, number of cards and a deck name), the Player Deck Card which is basically a Many-to-Many table which holds the Card Definition, the deck Reference as well as a Number field (which holds the position in the deck that the card is in) and finally my Card Definitions that I imported previously via my API calls.
I have a couple of goals here;
– I want to add the card to the deck in an ascending order, but I also want to give myself some room in future for the user to re-order their deck.
– I want to keep an accurate count of the number of cards in a deck at any time
– I want to block adding cards if the card count for the deck is going to exceed 12
– I want each card to be given a card number (basically the “deck position”) that is far enough away from the last card that we can slip cards in between, so I want them to increment by 100.
I start by taking the input – the deck reference and the card definition reference:

Next I want to stop the operation if the current Deck is already reporting 12 cards. I want to log this, but I also want to set a flow output for the subflow that reports the error (so that whatever system is calling it has an opportuntiy to record the error):

OK, so we don’t have a full deck. Is the card already in the deck? I can only have one copy at a time! Let’s check by looking up the specific combo in my target Player Deck Card table. If I find a record already, then that’s a problem so I’ll block that behaviour and end the subflow at that point:

If there are NO cards, then I also want to set a default card value, so let’s do a card lookup where we’re looking for just the last record in the deck by number:

If there’s something there we’ll increment by 100, otherwise we’ll set the Last Card number flow variable to 100 to start us off in the deck:

At this stage we can create our record!!! We want to set the card definition, the Player Deck reference, and the Card Number that we set before. We can then do a record count on that table to find out how many records there are currently and set that in our Player Deck record so that it has an accurate deck size.
Next thing we need to do is figure out how to manage card deletions from a deck… It looks like Flow Designer might not support delete operations, so we might need to get clever about this, or we might need to use our first bit of script/code in a Business Rule. We shall see!

Leave a Reply