Part 4: Creating a Deck

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:

Screenshot 2023 11 05 at 22 12 06

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):

Screenshot 2023 11 05 at 22 14 01

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:

Screenshot 2023 11 05 at 22 19 43

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:

Screenshot 2023 11 05 at 22 23 33

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:

Screenshot 2023 11 05 at 22 22 16

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!


Comments

One response to “Part 4: Creating a Deck”

  1. August Dunnihoo Avatar
    August Dunnihoo

    Luckily this step is pretty easy for my game since there is no deck builder aspect all I need to do is create the deck and randomize it based on the card database. I have created a “Playing Cards” table that is populated when creating the deck based off of the card database. This way I can have multiple games going on without making changes to the card instance.

Leave a Reply

Your email address will not be published. Required fields are marked *