> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kodeflowstudios.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating your first Dialogue

## Setup the UI

Create a basic dialogue UI with the following structure — the exact layout and styling is up to you:

* A speaker name text element (TextMeshPro)
* A dialogue text element (TextMeshPro)
* A way to trigger the next line (Button, keypress, etc.)

## Writing the Dialogue

Create a folder and name it `Resources`, this is where dialogue files live.

![Resources folder](https://cortado-bucket.lon1.cdn.digitaloceanspaces.com/dohttps://cortado-bucket.lon1.cdn.digitaloceanspaces.com/docs/resources/images/Parley/parley_resources_folder.png)

Now we have to create the folders that would hold the dialogue files – Parley's file path resolution works as follows: `Resources/{Language}/{FolderName}/{LanuguageCode}.{Name}` e.g. `Resources/English/Hello/en.Parley.yaml`

Create the file following the structure above — the `Resources` folder can live anywhere inside your project's `Assets` directory.

```YAML en.Parley.yaml icon=code theme={null}
Dialogue:
  node_1:
    Speaker: "Waiter"
    Text: "Welcome to Johnny's, What can I get you?"
    NextNode: node_2
  node_2:
    Speaker: "Patrick"
    Text: "Hey, I want some pasta but I can't really make my mind"
    NextNode: node_3
  node_3:
    Speaker: "Patrick"
    Text: "Do you have any recommendations?"
    NextNode: node_4
  node_4:
    Speaker: "Waiter"
    Text: "Of course sir! What do we think of the Chicken Alfredo pasta?"
    NextNode: node_5
  node_5:
    Speaker: "Patrick"
    Text: "Sounds great! I'll have that thanks."
    NextNode: null # or ommit this line entirely.
```

<Note>
  A node with no `NextNode` field, or a null one, is treated as the end of the dialogue.
</Note>

For the full YAML syntax reference, see [YAML Syntax](/parley/reference/yaml-syntax).

## Setting up the Script

With the file ready, let's get into the script.

Create a C# script and name it something like `HelloParley.cs` and let's get to writing it.

```C# HelloParley.cs icon=code theme={null}
using UnityEngine;
using TMPro;
using KodeFlowStudios.Parley.YamlCore;

public class HelloParley : MonoBehaviour
{
	public TMP_Text speakerNameText;
	public TMP_Text dialogueText;

	ParleyYaml parleyYaml;

	void Start()
	{
		Dialogue();
	}

	async void Dialogue()
	{
		// Area + conversation names match the folder/file layout under
		// Resources/{Language}/Hello/en.Parley.yaml.
		parleyYaml = new ParleyYaml("Hello", "Parley");

		while (parleyYaml.ConversationEnded != true)
		{
			speakerNameText.text = parleyYaml.CurrentNode.Speaker;
			dialogueText.text = parleyYaml.CurrentNode.Text;

			// await unblocks the next time the player presses the "advance"
			// input wired up inside Parley.
			await parleyYaml.OnNextDialogue;
		}

		parleyYaml = null;
	}
}
```

## Wiring things up

Back in the Unity editor, add the `HelloParley.cs` script to a GameObject in your scene, and set the `SpeakerNameText` and `DialogueText` variable fields to the text fields you made in the [UI](#setup-the-ui) section.

![Script Variable Fields](https://cortado-bucket.lon1.cdn.digitaloceanspaces.com/dohttps://cortado-bucket.lon1.cdn.digitaloceanspaces.com/docs/resources/images/Parley/parley_variable_fields.png)

## Testing

Hit play. Left click in the Game View to advance through the dialogue — you should see the speaker and text update with each click, and the dialogue ends cleanly on the last node.
