# Conversa Plugin

Reference Link: <https://github.com/enriquemorenotent/unity-conversa-support/wiki>

## Initial Updates to DiaManager.cs

{% code fullWidth="true" %}

```csharp
// Add to top of the script
using System;
using Conversa.Runtime.Events;
```

{% endcode %}

## Initial Updates to DiaTrigger.cs

{% code fullWidth="true" %}

```csharp
// Add to top of the script
using Conversa.Runtime;
using Conversa.Runtime.Events;
using Conversa.Runtime.Interfaces;

...

//Inside Class
[SerializeField] private Conversation conversation;
private ConversationRunner runner;

...

//Setting things up
private void Start()
{
	runner = new ConversationRunner(conversation);
	runner.OnConversationEvent.AddListener(HandleConversationEvent);
}


```

{% endcode %}

## Buckle up, Time for Delegates!

In javascript, you can pass a function as a variable. Not in C#. Now, you have to create a delegate. This video, up to 3:28 will explain the shenanigans. If you go past that, you will get confused.

{% embed url="<https://www.youtube.com/watch?v=3ZfwqWl-YI0>" %}

Just the additional Script added for DiaManager.

{% code fullWidth="true" %}

```csharp
//Adding Namespaces required
using System;

...

//Storing the function from the conversation starter script into this one
public delegate void NextMessageDelegate();
private NextMessageDelegate NextMessageFunction;

//Initializing it
private void Start()
{
...
    NextMessageFunction = NextMessage;
}

private void NextMessage()
{
    Debug.Log("Testing out this new thing, yo.");
}

//Having it as a separate function so you can drag and drop it into the PlayerInputComponent
//if the PlayerInputComponent is set to "Invoke Unity Events"
public void Advance(InputAction.CallbackContext ctx)
{
    if (ctx.performed)
    {
        NextMessageFunction();
    }
}

//In the Show Message option that opens up the Dialogue box
public void Show(string actor, string message, Sprite avatar, Action onContinue)
{
    ...
    NextMessageFunction = () => onContinue();
}

```

{% endcode %}

Here are some failures I got when trying to set "onContinue" to a function in the DiaManager:

{% code fullWidth="true" %}

```csharp
NextMessageFunction = onContinue();

NextMessage = onContinue;
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://roxioxx.gitbook.io/unity-cookbook/ui-onlyfans/dialogue-system/conversa-plugin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
