Importing and Exporting

## Introduction

In this section we're going to learn how you can use Perchance generators that you or others have made *inside* your generators.

## Importing

If you use Perchance long enough, you'll probably find that there are certain lists which you use quite often. These lists can be separated into their own generators and "imported" with a simple statement when needed.

Each generator on Perchance has a unique name that you can see in the url: "perchance.org/**name**" You can import other generators using their name. Let's import the perchance.org/noun generator:

```
sentence = The {import:noun} is sitting on my {import:noun}.

```

That'd result in something silly like "The brick is sitting on my cloud." There are pre-existing generators for a huge variety of topics. You can check out the useful generators list and also the Perchance community. If you create any generators that you think would be useful to others, please share them on on the community page!

In the example above, what if you want to get the `pluralForm` of an imported noun? In that case you can do this:

```
noun = {import:noun}
sentence = The [noun.pluralForm] are sitting on my [noun].

```

We've put the imported noun generator into its own `[noun]` list which we can then treat like any other list. You can use these curly import blocks wherever you use text. Here we've made a list out of a bunch of import statements:

```
livingThing
  {import:animal}
  {import:plant}
  {import:bacteria}

```

Often you'll want to import a specific list from *within* another generator. Let's imagine there's a generator called `animal-lists` with this code:

```
mammal
  kangaroo
  pig
  human

reptile
  lizard
  crocodile
  turtle

insect
  spider
  beetle
  ant

```

If you write `{import:animal-lists}` then you'll get "mammal" or "reptile" or "insect" as the output. That's probably not what we wanted. We want to be able to grab a random reptile, or a random insect - not a random animal "type". Here's how we do this:

```
animalLists = {import:animal-lists}
sentence
  That's definitely not {a} [animalLists.mammal]. It's {a} [animalLists.reptile].
  {A} [animalLists.insect] is much smaller than a {a} [animalLists.mammal].

```

Makes sense? We're just treating `[animalLists]` as if it's a list that we've defined in our code; we can access sub-lists, use `pluralForm`, `comsumableList`, and any other properties that we desire.

## Exporting

In the above example, what if you were the owner of the `animal-lists` generator and you wanted to make it so that if people write `{import:animal-lists}`, then they get a random animal instead of a random animal type? To do that, we need to add a special `$output` list:

```
$output
  [mammal]
  [reptile]
  [insect]

```

So now when they write `{import:animal-lists}`, the output will be a random item from whatever we've put in this `$output` list.

When sharing your generator, it's a good idea to give it a nice name. You can change your generator's name by clicking the "settings" button in the bar at the top of the editor.

Here's another example of how to use the special `$output` list:

```
$output = [description]

adjective
  narrow
  sturdy
  ...

thing
  chest
  cloak
  ...

description
  It's {a} [adjective] [thing] that looks about {10-70} years old.
  ...

```

Since we added the `$output` property, when people import our generator, they'll get a random `[description]`. If we don't include an `$output` property, then the importer would get "adjective", "thing" or "description" - i.e. the name of one of our top-level lists. That's because the list names in your generator are actually themselves *items* within the "root" list. If that's confusing, don't worry, it's not super important, but the above "Hierarchical Lists" section gives some more info on why this is the case. The main thing to understand is that you should make a top-level `$output` property that equals the list that you want importers to get when they import your generator. If you want to export *all* your lists, then you don't need to add a top-level `$output` property - Perchance assumes that by default.

To know more about importing and exporting, See Importing Generators and Exporting Generators.