Hello,

I am struggling with the output on this prompt generator, and I’ve tried to look up a solution and been unsuccessful so far. I honestly know nothing about coding other than what I’ve been learning in order to build perchance generators - so I know it may be something super simple I’m missing. Or I may have made it more complicated than it needs to be - or maybe what I want is something really complicated. I honestly don’t know. And I apologize if my lingo is awful!

The URL I’ve shared is an ultra-simplified version of the generator I am struggling with, and most of the list items have been eliminated so that what is left is guaranteed to duplicate the problem I’m having.

What I’m trying to accomplish with the current coding:

  1. That the generator defaults to 2 specific character names - Ed and Stede.
  2. That if a user inputs characters in the input box to customize their output that these two default characters do not show up. So not the user’s list + this default list being drawn from. Only the user’s list is drawn from if they input characters.
  3. That for certain output possibilities (line 1 for this simplified generator), whichever list is used is consumable so that a character’s name is not duplicated. For example, I would want “Ed can’t stop thinking about Stede,” not “Ed can’t stop thinking about Ed.” (I’ve attempted using [one] and [two] here.)

What is happening:

  1. The first time the page is loaded, or if it is refreshed, in the 1st line, where I’ve tried to use [one] and [two], it shows up as “undefined.” Once the generate button is clicked (and all subsequent clicks as long as the page is not refreshed), the output generates correctly.
  2. If I add custom characters in the user input box (let’s say “Jim” & “Olu”), on the first click of the generator button, only the 3rd line updates with these characters’ names. On the second click (and all subsequent clicks if the characters are left the same), all three lines show up with the correct characters.

So I would like it if I could figure out how to make it so that: a) the output loads correctly when the generator is first opened or immediately after the page is refreshed (no “undefined”) b) for the user input to show on all three lines once they’ve inputted their characters and clicked the generate button

Any help would be so greatly appreciated! Thank you for your time <3

  • wthit56@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    17 days ago

    I’ve made a separate example. While yours may have been simplified there was still a lot of complexity and redirection throughout the perchance code which made it hard to really know what’s what.

    This example does what you want (I think), and is also very simple. I hope it helps. https://perchance.org/hw714l9a98#edit

    • QuaintlyFig@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      16 days ago

      Thank you! Yes, this is fixing the issues I’ve been having perfectly!

      I apologize, I am still having trouble figuring out how to make these changes/fixes work in my generator. (Again, so un-tech-savvy over here - I’ve just gotten hooked on making generators and so it’s become a hyper-fixation!)

      I think the biggest thing I am “getting” is that you made / shown me a super cool way to have the default list built into the user input box in the HTML panel (I think that’s what it’s called) so I don’t need a separate “default” list over in the left-hand box (List panel?) where all the lists are. One less step in my wild Frankenstein approach! Very neat! I’m tickled pink!

      So I think I have two initial big questions that I’m simply not knowledgeable enough to figure out how to adapt with your lovely solution:

      1. Location of “body” or “output” information

      I think what I’m most confused about is that in the generator you’ve created, the output sentences (e.g. about tiddlywinks, etc) are in the right-hand box (HTML panel?).

      In my generator, I have that information under “body” in the left-hand box (List panel?) where I reference 3 separate lists (each of which in my full generator are very long lists: 50+ items on each) - in addition to the character names - for the generator to draw information from. Do I need to move the List panel’s “body”'s “text” information into the HTML box?

      2. Ability to output more than only 2 characters per prompt generated

      Additionally, while the default list of characters is 2 (Ed & Stede), folks can enter more than 2 characters, so I’d like the generator to draw from all possible characters. So, for example, if someone entered 4 characters (e.g. Jim, Olu, Archie, Zheng), the generated response could potentially include all 4 (rather than only a randomly chosen 2) except for the couple of spaces where I’ve gotten the [one] and/or [two] designated (because the response could be very nonsensical without those specifications - e.g. Archie & Jim have been on one date, and it’s the best date that Zheng has ever been on.).

      So this is my (very potentially quite bad/amateur) logic for having the [b], [c], and [q] lists (one for each line of output) and the [one] and [two] designations (for very specific possible prompts).

      For example, a possible output with 4 characters could be something like:

      Archie & Jim have been on one date, and it’s the best date that Archie has ever been on. Zheng says, “Blah blah blah.” Olu & Jim are best friends.

      OR, using your generator:

      Archie & Jim are strangers when Archie beats Jim at tiddlywinks. Archie & Olu are schoolmates, Archie bullied Olu.

      I am sorry if these are super dumb questions. Again, I know my approach in the coding is likely very convoluted as I’ve Frankensteined different parts together from the very little I’ve learned/gleaned/googled so far, so the amount of complexity and redirecting I’m sure are a result of my lack of know-how to allow for any degree of finesse. If you have the time and are willing, could you explain it to me like I’m a little bit dumb? I won’t be offended!

      I certainly don’t expect you to explain it to me - it’s truly just an ask if you are interested/willing.

      No matter what, I already so appreciate the time you’ve taken! So thank you! <3

      • QuaintlyFig@lemmy.worldOP
        link
        fedilink
        English
        arrow-up
        1
        ·
        16 days ago

        I figured most of this out! It’s very late here, so I’ll post tomorrow if I can with the additional fixes that let me have unreasonably high expectations of my generator’s capabilities!

        This absolutely would not have been possible without @wthit56@lemmy.world’s very cool example!! Thank you again, wthit56!!!

          • QuaintlyFig@lemmy.worldOP
            link
            fedilink
            English
            arrow-up
            1
            ·
            edit-2
            15 days ago

            I made another copy of my test generator to experiment with, so here’s the one where I’ve figured out the fixes:

            https://perchance.org/kzttwn1wna#edit

            1. I used your code to make the user input box in place of the other code I had originally used, and I just changed some of the names of things within it to match categories already in my generator (so I’d have to change fewer total things). Now every generated prompt shows the user inputted character names on the first click of the generate button (instead of only updating the 3rd line on the first click).

            2. I moved the line of code that defined [one] and [two] to above the line those categories are associated with in the body’s “text” output – that fixed the issue of those spots pulling up as “undefined” on the initial page load/refresh. (I felt like a dummy - but what a relief!)

            3. I changed this – [b] & [b] – to this – [one] & [two] – on the specific prompt possibilities where one or both characters are mentioned in the same line again. And I’ve left other prompt possibilities as [b] or [c] or [q] so that if a user inputs more than two characters, other characters can still show up on other lines of the prompt.


            I do have one last question I can’t seem to find a fix for. I’ve been unable to duplicate one part of how your example generator works. For my current generator, when the user inputs character names, the output updates on each “return” after entering each character name. I can’t figure out how to get it to remain static until the user has inputted all of the names they want and then only change when they press the generate button. I think it might be related to whatever I’m running into here:

            On my generator I left the button information as: onclick=“update()” — In your generator, it says: onclick=“update(output)”

            But when I put the word output inside the parentheses, my button stops working entirely. I haven’t been able to puzzle out what I’m doing or what I’m missing. Do you have any insight?

            Thank you again!

            • wthit56@lemmy.world
              link
              fedilink
              English
              arrow-up
              1
              ·
              14 days ago

              The onclick takes JS code. The JS function called “update” updates the perchance stuff across the whole page. If you pass an element to the update function, it will only update that element.

              So in my test, I have an element with the id “output.” So just passing output to the update() function means I’m passing a reference to that element with the id “output.” And then only that element is updated.