So obviously, it is a modification of the default sample one. I eventually want it to be able to generate an entire deck of unique cards for Caravan, and I don’t know yet how to get it to add jokers (which would need to remove the suit information)

I have been having trouble finding out where to look up this information.

  • VioneTM
    link
    English
    2
    edit-2
    8 months ago

    So first, on line 4, I was actually testing another solution which involves that select-until-plugin, but was not used in the final solution, so don’t mind that 😅. You can also delete the console.log(cards.size) since that was only used for debugging.

    Here are some explanations to the code: On line 9-10:

    • we create a new list named getCards.
    • Upon calling that list inside a square bracket e.g. [getCards], it would create a new JavaScript Set (which is an object that allows you to store unique items), then set is then referenced with the variable cards.
    • After creating the Set, we then call the selectCards list.

    On 14-15:

    • We create a new list called selectCards.
    • Upon calling that, it would first check if the cards.size (or number of items in the cards Set).
    • If the number is less than the specified num then it would ‘add’ an output on the Set with cards.add(output.evaluateItem).
    • The output is where you get the randomized cards that you have set up. We use .evaluateItem to it so it would only be a ‘text’ i.e. something like You have a 7 of spades from a Gammorah deck. and not You have [jokerornonjoker] from {a} [establishment] deck.
    • After adding to the Set, we then call again the selectCards, this will go through again the check, and if not, it would add again to the Set and go into a loop until the check for the size of the Set and the specified number has been met.
    • If the number is now greater than the specified num, it would then stop from the Loop and output the contents of the Set.
    • The Set is transformed into an Array with Array.from(cards) and using .selectAll and .joinItems('<br>') will neatly format them.

    Here are some references/resources to learn more about the code:

    Feel free to ask follow up questions!

    • @dlcnate1OP
      link
      English
      18 months ago

      so looking at it, the getcards list isn’t called for in the list itself, and is pulled up in the html right after the title. and this is what makes it ensure that there is no duplicates?

      i did get it to output between 30-60 which is what i want, i deleted the select-until-plugin nothing happened but when i tried removing console.log(cards.size) like you said, it broke it, so i put it back

      my updated generator with tweaks based on the code you gave me is here https://perchance.org/6903zy9slr

      • VioneTM
        link
        English
        2
        edit-2
        8 months ago

        so looking at it, the getcards list isn’t called for in the list itself, and is pulled up in the html right after the title. and this is what makes it ensure that there is no duplicates?

        Yes, the getCards is your main displaying output there which is why it is placed on the HTML, you can name them what you want if you prefer it having named output on the HTML, just need to rename some on the code. It isn’t the main code that is ensuring that there are no duplicates, the code for it is on the selectCards portion, but selectCards is also the one that displays it.

        but when i tried removing console.log(cards.size) like you said, it broke it, so i put it back

        You might need to also remove the comma after it e.g.

        ... (console.log(cards.size), cards.add(...), ...) : ...
        

        To

        ... (cards.add(...), ...) : ...