Remember-plugin

Link to Pluginhttps://perchance.org/remember-plugin

## Basic Overview

This plugin allows you to make it so certain variables are "remembered" even if you refresh the page. For example, if you were building a random text adventure game using the goto plugin, you could use this plugin to "remember" the player's hit points, experience points, etc. so that your players don't lose their progress if they close the browser tab or refresh it.

## Importing and Usage

### Importing

To use this plugin, put this code in your Perchance code panel (the main editor on the left-hand side):

```
remember = {import:remember-plugin}

```

Then write this **at the top** of your HTML panel (the bottom-right editor):

```
[remember(root, "a,b,c")]

```

Now the variables `a`, `b` and `c` will be remembered even after the page is reloaded. You can change `a`, `b` and `c` to whatever you want, and you can add as many of them as you want - just separate the variable names with commas like I've shown above.

### Usage

As an example, imagine that we had some code like this in our Perchance code panel:

```
num = {1-10}
output
  [if (a == undefined) {a = num.selectOne} else {a}]

```

And this code is at the top of our HTML code panel:

```
[remember(root, "a")]
[output]

```

So now when you first load the page, `a == undefined` will evaluate to `true` and so the `a = num.selectOne` code will get executed, and thus a random number will get output. But if you refresh the page, then `a == undefined` is no longer true because the `[remember(root, "a")]` code has loaded the `a` variable from last time, and so the old value of `a` gets output every time we reload the page.

### Clearing Saved Data

If you want to clear all the saved data, then just execute this code: `[remember(root, "@forget")]`. But note that this will **reload** the page as well. So, if you wanted to make a button that clears all the user's saved data, then you'd put this in your HTML panel:

```
<button onclick="remember(root, '@forget')">clear data</button>

```
Note that you don't need to put square brackets around code in HTML `onclick` attributes. Also note that you need to use single quotation marks (`'`) around `@forget` since HTML attributes (like `onclick`) use double quotation marks to mark their start and end.

### Remembering HTML Inputs

You can also use this plugin to remember the values in text inputs, drop-down menus, and other types of user inputs. You can learn how to add user inputs in the "User Inputs" section at perchance.org/examples. Here's how you can remember user inputs:

```
[remember(root, "@inputs")]

```

And you can remember both variables and user inputs like this:

```
[remember(root, "@inputs,myVariable,myOtherVariable")]

```

And, by the way, you can add spaces between the variable names if you prefer. Just make sure there are commas between them:

```
[remember(root, "@inputs, myVariable, myOtherVariable")]

```

## Notes

* Here's a very simple example of how to use it.
* Here's an example that includes some buttons to change the variable that's being remembered.
* Here's a basic example showing how to remember a variety of user inputs.
* Here's an example of how to remember user **text inputs, range slider,** **checkbox** inputs.
* Here's an example of how to use the remember and goto plugins together to people can save the current state in their text adventure and come back to it later.
* Here's an example of how to "remember" arrays/lists of items (advanced, ask on the forum if you need help)
* If you change the URL of your generator, the remembered data will be lost. You can change the URL back to the orignal version to recover the data.