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:
- That the generator defaults to 2 specific character names - Ed and Stede.
- 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.
- 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:
- 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.
- 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
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 @[email protected]’s very cool example!! Thank you again, wthit56!!!
Well done! If you let me know where to look, I'll check it out :D
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
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).
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!)
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!
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.