this post was submitted on 22 Mar 2024
4 points (100.0% liked)

Perchance - Create a Random Text Generator

465 readers
10 users here now

⚄︎ Perchance

This is a Lemmy Community for perchance.org, a platform for sharing and creating random text generators.

Feel free to ask for help, share your generators, and start friendly discussions at your leisure :)

This community is mainly for discussions between those who are building generators. For discussions about using generators, especially the popular AI ones, the community-led Casual Perchance forum is likely a more appropriate venue.

See this post for the Complete Guide to Posting Here on the Community!

Rules

1. Please follow the Lemmy.World instance rules.

2. Be kind and friendly.

  • Please be kind to others on this community (and also in general), and remember that for many people Perchance is their first experience with coding. We have members for whom English is not their first language, so please be take that into account too :)

3. Be thankful to those who try to help you.

  • If you ask a question and someone has made a effort to help you out, please remember to be thankful! Even if they don't manage to help you solve your problem - remember that they're spending time out of their day to try to help a stranger :)

4. Only post about stuff related to perchance.

  • Please only post about perchance related stuff like generators on it, bugs, and the site.

5. Refrain from requesting Prompts for the AI Tools.

  • We would like to ask to refrain from posting here needing help specifically with prompting/achieving certain results with the AI plugins (text-to-image-plugin and ai-text-plugin) e.g. "What is the good prompt for X?", "How to achieve X with Y generator?"
  • See Perchance AI FAQ for FAQ about the AI tools.
  • You can ask for help with prompting at the 'sister' community Casual Perchance, which is for more casual discussions.
  • We will still be helping/answering questions about the plugins as long as it is related to building generators with them.

6. Search through the Community Before Posting.

  • Please Search through the Community Posts here (and on Reddit) before posting to see if what you will post has similar post/already been posted.

founded 1 year ago
MODERATORS
 

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.

you are viewing a single comment's thread
view the rest of the comments
[–] Alllo 2 points 8 months ago* (last edited 8 months ago) (7 children)

lovely first generator.

here's how i would do it: https://perchance.org/itwge1c592

im going to delete that page in a day or two btw. i think it does what you want and is a next step in what you are learning as a second list with gears and moving parts in it

[–] dlcnate1 2 points 8 months ago (6 children)

Thank you, I have tweaked the original, but I made the joker chance 1/27 and gave it option of with and without a trademark.

I guess the next step now is to figure out how to make it output multiple cards at once, and then how to have those outputs be unique. As the rules of caravan allow you to have multiple kings of spades, so long as they are from different decks.

[–] VioneT 2 points 8 months ago (4 children)

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.

[–] dlcnate1 2 points 8 months ago (1 children)

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.

[–] VioneT 2 points 8 months ago* (last edited 8 months ago) (1 children)

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!

[–] dlcnate1 1 points 8 months ago (1 children)

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

[–] VioneT 2 points 8 months ago* (last edited 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(...), ...) : ...
load more comments (2 replies)
load more comments (3 replies)
load more comments (3 replies)