# API-reference

### Core Loop

#### Launch MiniTon

This method is overloaded

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

```csharp
void MiniTonCrossPlatform.LaunchMiniTon();
```

Legacy:

```csharp
void MiniTonCrossPlatform.LaunchMiniTon(MiniTonMatchDelegate matchDelegate);
```

**Parameters**

Legacy: `matchDelegate` A reference to a `MiniTonMatchDelegate` instance that MiniTon will use
{% endtab %}

{% tab title="Synchronous" %}

```csharp
void MiniTonCrossPlatform.LaunchMiniTon();
```

Legacy:

{% code overflow="wrap" %}

```csharp
void MiniTonCrossPlatform.LaunchMiniTon(MiniTonMatchDelegate matchDelegate);
```

{% endcode %}

**Parameters**[**​**](https://docs.skillz.com/docs/api-reference/#parameters-1)

Legacy: `matchDelegate` A reference to a `MiniTonMatchDelegate` instance that MiniTon will use
{% endtab %}
{% endtabs %}

***

#### Update Current Score

Call this method every time the player's score changes during a MiniTon match.

This method is overloaded

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

```csharp
void MiniTonCrossPlatform.UpdatePlayersCurrentScore(string score);
```

**Parameters**

`score` The player's current score as a string
{% endtab %}

{% tab title="int" %}

```csharp
void MiniTonCrossPlatform.UpdatePlayersCurrentScore(int score);
```

**Parameters**

`score` The player's current score as a integer
{% endtab %}

{% tab title="float" %}

```csharp
void MiniTonCrossPlatform.UpdatePlayersCurrentScore(float score);
```

**Parameters**

`score` The player's current score as a float
{% endtab %}
{% endtabs %}

***

#### Submit Score

Call this method when a player finishes a match. This will send the score to MiniTon and conclude the match. This will **not** send the user back to the MiniTon BOT

This method is overloaded

{% tabs %}
{% tab title="string" %}
{% code overflow="wrap" %}

```csharp
void MiniTonCrossPlatform.SubmitScore(string score, Action successCallback, Action<string> failureCallback)
```

{% endcode %}

**Parameters**

`score` Player's final score as a string

`successCallback` Implementation of the System.Action delegate that handles successful submission

`failureCallback` Implementation of the System.Action delegate that handles failed submission
{% endtab %}

{% tab title="int" %}

```csharp
void MiniTonCrossPlatform.SubmitScore(int score, Action successCallback, Action<string> failureCallback)
```

**Parameters**

`score` Player's final score as an integer

`successCallback` Implementation of the System.Action delegate that handles successful submission

`failureCallback` Implementation of the System.Action delegate that handles failed submission
{% endtab %}

{% tab title="float" %}

```csharp
void MiniTonCrossPlatform.SubmitScore(float score, Action successCallback, Action<string> failureCallback)
```

**Parameters**

`score` Player's final score as a float

`successCallback` Implementation of the System.Action delegate that handles successful submission

`failureCallback` Implementation of the System.Action delegate that handles failed submission
{% endtab %}
{% endtabs %}

***

#### End Replay

End the current replay if one exists and returns the status of the score submission. Must be called after score has been submitted. Use to end replay recording at conclusion of the match and before user is presented with personalized progression room metrics.

```csharp
bool EndReplay()
```

**Returns**

Boolean true if end replay was successful, false if the user has not submitted a score for the match

***

#### Return to MiniTon

The ReturnToMiniTon method presents the MiniTon BOT. This must be called after the score has been submitted with the SubmitScore method. After the SubmitScore has been called you can present users with relevant statistics such as high score and present content to enhance the game experience.

In all cases, it will return a boolean, indicating whether or not it is able to return the user to MiniTon. For the case of a match in progress, unless a score has been submitted, this method will return false and the user will not be returned to MiniTon. If a score has been submitted, it returns true and returns the user to MiniTon.

```csharp
bool MiniTonCrossPlatform.ReturnToMiniTon()
```

**Returns**

Boolean indicating whether it is able to return the user to MiniTon BOT

***

#### Abort Match

Forfeits the current match and returns to the MiniTon BOT.

```csharp
void MiniTonCrossPlatform.AbortMatch()
```

***

#### Display Tournament Results With Score

The DisplayTournamentResultsWithScore method replaces the deprecated ReportFinalScore method. MiniTon recommends that you try to use the SubmitScore and ReturnToMiniTon methods. However, DisplayTournamentResultsWithScore can be used as a failsafe if the SubmitScore method fails.

This method is overloaded

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

```csharp
void MiniTonCrossPlatform.DisplayTournamentResultsWithScore(string score)
```

**Parameters**

`score` Player's final score as a string
{% endtab %}

{% tab title="int" %}

```csharp
void MiniTonCrossPlatform.DisplayTournamentResultsWithScore(int score)
```

**Parameters**

`score` Player's final score as an integer
{% endtab %}

{% tab title="float" %}

```csharp
void MiniTonCrossPlatform.DisplayTournamentResultsWithScore(float score)
```

**Parameters**

`score` Player's final score as a float
{% endtab %}
{% endtabs %}

***

### Progression API

#### Progression Namespace Constants

Calls to the progression methods **must use one of the three namespace** `string` values. Each namespace return a separate list of key-value pairs for for that namespace:

* `DefaultPlayerData` For read-only MiniTon player data and is game-specific.
* `PlayerData` For publisher-defined player data and is game-specific.
* `InGameItems` For publisher-defined player data and is shared across all games in publisher's portfolio.

```csharp
ProgressionNamespace.DEFAULT_PLAYER_DATA
ProgressionNamespace.PLAYER_DATA
ProgressionNamespace.IN_GAME_ITEMS
```

***

#### Get Progression User Data

Retrieve data for the current user. This method requires `callback` methods that allow you to handle success and fail scenarios.

```csharp
void MiniTonCrossPlatform.GetProgressionUserData(string progressionNamespace, List<string> userDataKeys, Action<Dictionary<string, ProgressionValue>> successCallback, Action<string> failureCallback)
```

**Parameters**

`progressionNamespace` One of the Namespace String Constants

`userDataKeys` String key list of desired fields.

`successCallback` Action delegate to handle successful callback. The method must be defined in the implementation.

`failureCallback` Action delegate to handle failed callback. The method must be defined in the implementation.

***

#### Update Progression User Data

Write data for the current user. This method requires `callback` methods that allow you to handle success and fail scenarios. Can update up to 25 elements per call.

> **Note**
>
> The **DefaultPlayerData** namespace is read-only, and cannot be used with this method.

{% code overflow="wrap" %}

```csharp
void MiniTonCrossPlatform.UpdateProgressionUserData(string progressionNamespace, Dictionary<string, object> userDataUpdates, Action successCallback, Action<string> failureCallback)
```

{% endcode %}

**Parameters**

`progressionNamespace` One of the Namespace String Constants

`userDataUpdates` Dictionary of key/value pairs to be updated

`successCallback` Action delegate to handle successful callback. The method must be defined in the implementation

`failureCallback` Action delegate to handle failed callback. The method must be defined in the implementation

***

### Random Generator

#### Random Value

Use the MiniTon random implementation to ensure each competitor receives the exact same random number.

```csharp
float MiniTonCrossPlatform.Random.Value()
```

**Returns**

A generated pseudo random float value

***

#### Random Value Ranged

This method is overloaded

{% tabs %}
{% tab title="int" %}
{% code overflow="wrap" %}

```csharp
int MiniTonCrossPlatform.Random.Range(int min, int max)
```

{% endcode %}

**Parameters**

`min` The minimum int value for the range`max` The maximum int value for the range

**Returns**

A generated pseudo random int value within the given range

> **NOTE**
>
> The Random function `Range(int min, int max)` requires the min and max value range (max-min) to be no larger than `Int.MaxValue` to prevent overflow
> {% endtab %}

{% tab title="float" %}

```csharp
float MiniTonCrossPlatform.Random.Range(float min, float max)
```

**Parameters**[**​**](https://docs.skillz.com/docs/api-reference/#parameters-71)

`min` The minimum float value for the range

`max` The maximum float value for the range

**Returns**[**​**](https://docs.skillz.com/docs/api-reference/#returns-25)

A generated pseudo random float value within the given range

> **NOTE**[**​**](https://docs.skillz.com/docs/api-reference/#note-2)
>
> The Random function `Range(float min, float max)` requires the min and max value range (max-min) to be no larger than `Float.MaxValue` to prevent overflow
> {% endtab %}
> {% endtabs %}

***

#### Random Point Inside Unit Sphere

Generate a point inside the unit sphere using `Value()`.

```csharp
Vector3 MiniTonCrossPlatform.Random.InsideUnitSphere();
```

**Returns**

A new [`Vector3`](https://docs.unity3d.com/ScriptReference/Vector3.html) object

***

#### Random Point Inside Unit Circle

Find a point inside the unit circle using `Value()`.

```csharp
Vector2 MiniTonCrossPlatform.Random.InsideUnitCircle();
```

**Returns**

A new [`Vector2`](https://docs.unity3d.com/ScriptReference/Vector2.html) object

***

#### Random Point On Unit Sphere

Hybrid rejection / trig method to generate points on a sphere using `Value()`.

```csharp
Vector3 MiniTonCrossPlatform.Random.OnUnitSphere();
```

**Returns**

A new [`Vector3`](https://docs.unity3d.com/ScriptReference/Vector3.html) object

***

#### Random Quaternion in Rotation

Quaternion random using `Value()`.

```csharp
Quaternion MiniTonCrossPlatform.Random.Rotation();
```

**Returns**

A new [`Quaternion`](https://docs.unity3d.com/ScriptReference/Quaternion.html) object

***

#### Random Quaternion in Rotation Uniform

Quaternion random using `Value()`.

```csharp
Quaternion MiniTonCrossPlatform.Random.RotationUniform();
```

**Returns**

A new [`Quaternion`](https://docs.unity3d.com/ScriptReference/Quaternion.html) object

***

### Helpers

#### Get Match Info

```csharp
MiniTonSDK.Match MiniTonCrossPlatform.GetMatchInfo();
```

**Returns**

A [`Match`](#match-info) object containing information about the current match in progress

***

#### Get Match Rules

Returns the match gameplay parameters that you set up in the MiniTon Developer Console for each tournament type

```csharp
Hashtable MiniTonCrossPlatform.GetMatchRules();
```

**Returns**

`Hashtable` containing the gameplay parameters of the current match

***

#### Get Player

Gets the currently logged-in player info. This will return an empty object if a MiniTon player has not been created yet.&#x20;

```csharp
MiniTonSDK.Player MiniTonCrossPlatform.GetPlayer();
```

**Returns**

A [`Player`](#player-info) object

***

#### Get SDK Version

Gets the version of the MiniTon SDK your game is being run on.

```csharp
string MiniTonCrossPlatform.SDKVersionShort();
```

**Returns**

MiniTon SDK version as a string

***

#### Is Match In Progress

Checks if a match is currently in progress.

```csharp
bool MiniTonCrossPlatform.IsMatchInProgress();
```

**Returns**

A boolean indicating if a match if is in progress

***

#### Set Metadata for Match In Progress

Updates the meta data for a MiniTon match in progress to track player actions, level types, or other information pertinent to the MiniTon integration. There should be no more than 10 key/value pairs in the supplied collection. Data will only be available to MiniTon to help identify fairness in level-based games.

```csharp
void MiniTonCrossPlatform.AddMetadataForMatchInProgress(string metadataJson, bool forMatchInProgress)
```

**Parameters**

`attributes` String representing the meta data in a JSON string

`forMatchInProgress` Boolean to check whether the user is in a MiniTon game

***

***

### Sync API

#### Is Match Completed

This will return whether or not another client connected to this match has called either `displaySynchronousTournamentResultsWithScore` or `initiateSynchronousAbortWithCompletion:` to end the match.

```csharp
bool MiniTonCrossPlatform.IsMatchCompleted()
```

**Returns**

Boolean indicating whether or not the match has been completed

***

#### Send Data

Sends a message to all clients connected to this match. This will trigger `MiniTonSyncDelegate::onDidReceiveData:` on all clients connected to the current match.

> Note:&#x20;
>
> `NSData` passed to this function are limited to a certain size based on the game, and this function will assert if over that size. (2048 bytes currently).

```csharp
void MiniTonCrossPlatform.SendData(byte[] data)
```

**Parameters**

`data` The message to be sent, max 2048 bytes

***

### Objects

#### Real-Time Server Connection Info

**`CustomServerConnectionInfo`**

| Property   | Data Type | Description                                                 |
| ---------- | --------- | ----------------------------------------------------------- |
| isBotMatch | bool      | Indicates if the match is a sync bot match                  |
| MatchId    | string    | The ID of the real-time match                               |
| MatchToken | string    | An encrypted token to help validate the session server side |
| ServerIp   | string    | The hostname or IP for the match                            |
| ServerPort | string    | The port for the game server                                |

***

#### Match Info

**`Match`**[**​**](https://docs.skillz.com/docs/api-reference/#match)

| Property                   | Data Type                    | Description                                                                                         |
| -------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------- |
| BracketRound               | int                          | Indicates the round of the bracket tournament if IsBracket is true                                  |
| CustomServerConnectionInfo | CustomServerConnectionInfo   | The connection info to a custom server that coordinates a real-time match                           |
| Description                | string                       | The description of this tournament type                                                             |
| EntryToncoin               | float                        | If this tournament is being played for Toncoin, this is the amount of Toncoin required to enter     |
| EntryPoints                | int                          | If this tournament is being played for Points, this is the amount of Points required to enter.      |
| GameParams                 | Dictionary\<string, string>  | The custom parameters for this tournament type specified in the developer portal                    |
| ID                         | ulong                        | The unique ID for the match                                                                         |
| IsBracket                  | bool                         | Indicates the match is a bracketed tournament                                                       |
| IsToncoin                  | bool                         | Indicates the match is for Toncoin prizes or for Points                                             |
| IsCustomSynchronousMatch   | bool                         | Indicates if the match is a sync match                                                              |
| IsSynchronous              | bool                         | Deprecated. Indicates if this match is Sync. Note: please use the IsCustomSynchronousMatch property |
| IsTieBreaker               | bool                         | Indicates whether the match is a tie-breaker                                                        |
| Name                       | string                       | Name of the match                                                                                   |
| Players                    | List<[Player](#player-info)> | List of players in the match                                                                        |
| MiniTonDifficulty          | uint                         | The difficulty of the game (used with automatic difficulty). Note: only set in production.          |
| TemplateID                 | int                          | The unique ID for the tournament template this match is based on                                    |

***

#### Player Info

**`Player`**

| Property           | Data Type | Description                                             |
| ------------------ | --------- | ------------------------------------------------------- |
| AvatarURL          | string    | A link to the user's avatar image                       |
| DisplayName        | string    | Player name                                             |
| FlagURL            | string    | A link to the user's country's flag image               |
| ID                 | ulong     | The Telegram ID unique to this user                     |
| IsCurrentPlayer    | bool      | This Player represents the current user if this is true |
| TournamentPlayerID | ulong     | A Tournament Player ID unique to this user              |

***

#### Progression Metadata

**`ProgressionMetadata`**

| Property | Data Type     | Description                                                   |
| -------- | ------------- | ------------------------------------------------------------- |
| GameIds  | List\<string> | List of relevant game IDs for the associated ProgressionValue |

***

#### Progression Value

**`ProgressionValue`**

| Property        | Data Type           | Description                                                               |
| --------------- | ------------------- | ------------------------------------------------------------------------- |
| DataType        | string              | The data type for the stored value                                        |
| DisplayName     | string              | The display name for the stored value                                     |
| LastUpdatedTime | DateTime            | The timestamp of when the data was last updated on MiniTon servers in UTC |
| Metadata        | ProgressionMetadata | The metadata for this progression value                                   |
| Value           | string              | The stored value for this progression value                               |
