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.
https://perchance.org/ppjwmof8n5
Here is my modification of your generator. We can use JavaScript’s Set to create a unique array of items.
We first create the Set, and then we call the loop list.
First it checks if the Set’s size is less than the aimed number of outputs. If yes, then it would add another item on the Set and return to loop. Otherwise, if the Set’s Size is the same as the aimed number of outputs, then it would then return the Set to an Array, and use the Perchance .selectAll and .joinItems to format them.
I appreciate it, but I gotta admit, when I look at the changes allo made I was able to understand them.
But when I look at the changes you made, I don’t know what is actually happening in the code. I was hoping to get an idea of what’s going on, in the hopes that I can recreate it for future generators without having to ask every time.
lines 4, 9-10, and 14-15
And also, will this work in a way to make it so that it generates a random amount as well? between 30-60? I figure line 12 could be changes to a degree.
So first, on
line 4
, I was actually testing another solution which involves thatselect-until-plugin
, but was not used in the final solution, so don’t mind that 😅. You can also delete theconsole.log(cards.size)
since that was only used for debugging.Here are some explanations to the code: On
line 9-10
:getCards
.[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 variablecards
.selectCards
list.On
14-15
:selectCards
.cards.size
(or number of items in thecards
Set).num
then it would ‘add’ anoutput
on the Set withcards.add(output.evaluateItem)
.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 likeYou have a 7 of spades from a Gammorah deck.
and notYou have [jokerornonjoker] from {a} [establishment] deck.
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.num
, it would then stop from the Loop and output the contents of the Set.Array.from(cards)
and using.selectAll
and.joinItems('<br>')
will neatly format them.Here are some references/resources to learn more about the code:
.selectAll
and.joinItems
Feel free to ask follow up questions!
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 removingconsole.log(cards.size)
like you said, it broke it, so i put it backmy updated generator with tweaks based on the code you gave me is here https://perchance.org/6903zy9slr
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 namedoutput
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 theselectCards
portion, butselectCards
is also the one that displays it.You might need to also remove the comma after it e.g.
... (console.log(cards.size), cards.add(...), ...) : ...
To
... (cards.add(...), ...) : ...