> For the complete documentation index, see [llms.txt](https://docs.yarnspinner.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yarnspinner.dev/2.4/api/csharp/yarn.unity/yarn.unity.dialoguerunner/yarn.unity.dialoguerunner.addfunction-2.md).

# AddFunction(string,System.Func\<TResult>)

Method in [DialogueRunner](/2.4/api/csharp/yarn.unity/yarn.unity.dialoguerunner.md)

## Summary

Add a new function that returns a value, so that it can be called from Yarn scripts.

```csharp
public void AddFunction<TResult>(string name, System.Func<TResult> implementation);
```

## Remarks

When this function has been registered, it can be called from your Yarn scripts like so:

```
<<if myFunction(1, 2) == true>>
myFunction returned true!
<<endif>>
```

The `call` command can also be used to invoke the function:

```
<<call myFunction(1, 2)>>
```

## Parameters

| Name                           | Description                                                                |
| ------------------------------ | -------------------------------------------------------------------------- |
| `Func<TResult>` implementation | The `System.Delegate` that should be invoked when this function is called. |
| `string` name                  |                                                                            |

## Type Parameters

| Name    | Description                                            |
| ------- | ------------------------------------------------------ |
| TResult | The type of the value that the function should return. |

## See Also

* [Library](/2.4/api/csharp/yarn/yarn.library.md): A collection of functions that can be called from Yarn programs.
