So, I want the make generator to remember user inputs and the latest generated output using the remember plugin, it works on user input but not for the output. I know there’s a solution for this since generators like AI Chat can remember the chat logs without problem but I’m too dumb to understand the code lol

Also, how can I prevent the AI to automatically generate output on first load? I’m using the firstload = true tingy but I want to make it look cleaner when the generator loads since it 's displaying the [firstLoad ? "" : output] for a split second, is there any other method for this?

  • VioneTM
    link
    English
    212 days ago

    Can you share the generator you are working on? You could set a variable that is attached to the remember plugin, then upon generation, update that variable with the generated output. Then upon load of the page, you would then retrieve that from the remember plugin and display it. As for preventing it to run, you could remove it, then on the button you use to ‘update()’, you can have idOfContainer.innerHTML = ai(output) to set the output of the ai to that container.

    • darkXploreOP
      link
      English
      1
      edit-2
      10 days ago

      I’m just making random generators atm, trying to figure out how it works for later use since I’m not really active in the platform, but I’ve tried putting the output alongside with the @inputs to the plugin code like this: [remember(root, "@inputs,output")] and got an error message like this:

      It appears that you’ve got a mismatch in your opening and closing square brackets. For each opening square bracket, there should be a closing one. If you’d like to use a literal square bracket (i.e. you want to actually display one, rather than using them to output a random list item, then you need to put a “backslash” before it like “[ … ]”. Here’s the text that seems to be causing the error:

      It seems the plugin is currently not supporting AI output text, also, thanks for the output suggestion!

      EDIT: I think I’ve figured out the solutions for both of my problems thanks to AI code helper 👍

  • TAPgiles
    link
    English
    212 days ago

    You can use localStorage to save and restore things with code. I believe that’s what the remember plugin uses to save things anyway.

    So you’d do something like localStorage.setItem("last generated", data.generatedText) which will save it. And when you load, you can use loaded = localStorage.getItem("last generated"); if (loaded) { element.innerText = loaded; } which would put the text in an element with the id “element”, if there was anything stored in the first place.

    You can look up more about localStorage on MDN.

    • darkXploreOP
      link
      English
      1
      edit-2
      10 days ago

      Sorry for the late response, unfortunately, I’m just started learning coding recently, especially JS, I might need to read a bit more about this lol thanks for the link!

      EDIT: Just wanted to let you know that I’ve figured out a solution thanks to the AI code helper, it basically wrote the similar function:

      // Function to load data from local storage when the page loads
        function loadData() {
          userInputEl.value = localStorage.userInput || ""; // Load user input
          aiOutputEl.value = localStorage.aiOutput || ""; // Load AI output
        }
      
        // Function to save data to local storage whenever there's an input change
        function saveData() {
          localStorage.userInput = userInputEl.value; // Save user input
          localStorage.aiOutput = aiOutputEl.value; // Save AI output
        }
      
      window.onload = loadData;
      

      And just simply put the oninput="saveData() into both input and output elements.

      • TAPgiles
        link
        English
        110 days ago

        Yep that looks good 👍