# Invoke Trigger from Game

In this How-to, we’ll go through the process of invoking a created trigger from the game client.

## Prerequisites

* [A LootLocker account and a created game](https://lootlocker.com/sign-up)
* One or multiple triggers [setup in the web console](https://docs.lootlocker.com/game-systems/triggers/how-to/setting-up-triggers-in-console)
* [An active Game Session](https://docs.lootlocker.com/players/authentication)

When invoking triggers, you can specify to either invoke one or multiple triggers in the function.

{% tabs %}
{% tab title="Unity" %}

```csharp
// If you want to check and notify the player of what they received, save the keys of the successfully invoked triggers
List<string> successfulKeys = new List<string>();
LootLockerSDKManager.InvokeTriggersByKey(new string[] { "key_one", "key_two" }, (response) =>
{
    if (response.success)
    {
        // Even if keys fails, the call is successful, so you need to check which triggers were successful and which ones failed
        foreach (var item in response.Successful_keys)
        {
            Debug.Log("Key " + item.Key + " was successfully invoked.");
            // Save this key if you want the check what the player got
            successfulKeys.Add(item.Key);
            // Add your own code here to handle successful keys
        }
        foreach (var item in response.Failed_keys)
        {
            Debug.LogWarning("Key " + item.Key + " failed with reason:"+item.reason);
            // Add your own code here to handle the error
        }
        
        // Here you would put code to check notifications for what the player received.
    }
    else
    {
        Debug.Log(response.errorData.message);
        // Add your own code here to handle the error
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-5d3686d31ff73e45c69bb34ca5f48cdc129bd6d5%2FhowTo-InvokeTriggerFromGame-Blueprint.png?alt=media" alt=""><figcaption><p>Blueprint example of how to invoke triggers from your game. To copy the example, see <a href="https://blueprintue.com/blueprint/4b53am-0/">https://blueprintue.com/blueprint/4b53am-0/</a>.</p></figcaption></figure>

Above is an example of how to invoke triggers using blueprints in Unreal Engine. For an example you can copy and paste into your editor, [look here](https://blueprintue.com/blueprint/0t9ggps3/).

There are a few things to note from this example.

* Firstly, even if the request succeeds there may be triggers that failed invocation. Because of this, you should always check the `Failed_keys` list from the response.
* And secondly, the returned information does not tell you what has been rewarded to the player. For that you will want to check the player's [notifications](https://docs.lootlocker.com/shared-systems/notifications/how-to/list-notifications-mark-read). If you want to do this, then you will want to store the keys of the sucessfully invoked triggers to identify which notifications correspond to which trigger.
  {% endtab %}

{% tab title="REST" %}

```bash
curl --location --request POST 'https://api.lootlocker.io/game/triggers/cozy-crusader/v1' \
--header 'x-session-token: 3266edd928f5769545425469ac417fee456d8367' \
--header 'Content-Type: application/json' \
--data-raw '{
    "keys": [
        "key1",
        "key2",
        "key3"
    ]
}'
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
When sending the same trigger multiple times in the same request, it will only invoke once. To invoke the same trigger multiple times, it needs to be invoked in multiple functions.
{% endhint %}

### Conclusion

In this How-to, we’ve invoked a trigger to reward the player. After you’ve gotten successful key responses, [you may check to see the specific rewards given to the player](https://docs.lootlocker.com/shared-systems/notifications/how-to/list-notifications-mark-read).
