Skip to main content
Version: 28.0.18

Set Up Core Loop & Gameplay

Overview

Below, we walk your through the core elements of setting up your core loop and gameplay on Skillz. Beginning with starting a match, reporting a score and eventually getting back to the Skillz UI. By the end of this article, you will have a complete core loop allowing you to fully test a standard Skillz match.

Before continuing, make sure you have completed the previous steps - Launch the Skillz UI.

Launching Your Gameplay

When Skillz launches, it will take control of the user experience. The player will start a match and Skillz will notify the game. At this point, control is given back to your game to start the match gameplay. The examples below illustrate how to handle starting a match.

You should have previously implemented the SkillzMatchDelegate interface but likely only included the stubbed in functions. To handle a match start, you need to expand your implementation of OnMatchWillBegin.

From within OnMatchWillBegin you should:

  1. Clear any previously stored match settings
  2. Retrieve the Match object and utilize it to set gameplay parameters
  3. Load your game scene
SkillzGameController.cs
// ...
public void OnMatchWillBegin(Match matchInfo) {
SceneManager.LoadScene("GameplayScene");
}
// ...

Completing Gameplay

Submit Score

To ensure that both asynchronous and synchronous gameplay proceeds optimally, the score for the match should be submitted immediately using SubmitScore when the match ends, regardless of any remaining player input necessary to reach the match results screen. The score submission should be handled in the background without any explicit action by the player necessary to proceed.

The SubmitScore method is expecting three values - a score as well as Success and Failure Callbacks.

You should report the final score from a script that controls your game scene logic.

MatchController.cs
using Skillz;
using UnityEngine;

public class MatchController : MonoBehaviour
{
void TryToSubmitScore() {
string score = GetScore();
SkillzCrossPlatform.SubmitScore(score, OnSuccess, OnFailure);
}

void OnSuccess() {
Debug.Log("Success");
}

void OnFailure(string reason) {
Debug.LogWarning("Fail: " + reason);
StartCoroutine(RetrySubmit());
}

IEnumerator RetrySubmit() {
yield return new WaitForSeconds(_retrySeconds);
TryToSubmitScore();
}
}

Note on Progression

After submitting a score, you have the opportunity to present the player with a granular score breakdown and an opportunity to allow the player to view their game progression. Setup for this is detailed further in the Progression Overview.

Ending Replay

Many cash matches are recorded in order to allow players to view replays as well as allow Skillz to monitor fair play. The SDK provides an option that will allow you to end the replay after successfully submitting scores before progressing. This prevents unnecessarily long replays when the players interact with other gameplay elements like Progression. If you choose not to manually end the replay, the replay will end when the game returns to the Skillz UI.

You might want to consider supporting this feature in your game to allow users more control to conserve on resources i.e. battery, network etc.

If you invoke this method before calling SubmitScore a value of false will be returned. It is always recommended, to submit the player score as soon as the match gameplay ends, if possible.

bool success = SkillzCrossPlatform.EndReplay();

Return To The Skillz UI

The ReturnToSkillz method exits your gameplay scene and presents the Skillz UI. This must be called after the score has been successfully submitted with the SubmitScore method. After SubmitScore has been called, you can present users with high scores or progression systems to enhance the game experience before ultimately calling the ReturnToSkillz method and loading the Skillz UI.

In all cases, it will return true or false, depending on whether or not it is able to return the user to Skillz. 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 Skillz. If a score has been submitted, it returns true and returns the user to Skillz.

The ReturnToSkillz method provides flexibility on how to hand the end of the match behavior.

MatchController.cs
using Skillz;
using UnityEngine;

public class MatchController : MonoBehaviour
{
void TryToSubmitScore() {
string score = GetScore();
SkillzCrossPlatform.SubmitScore(score, OnSuccess, OnFailure);
}

void OnSuccess() {
Debug.Log("Success");
MatchComplete();
}

void OnFailure(string reason) {
Debug.LogWarning("Fail: " + reason);
StartCoroutine(RetrySubmit());
}

IEnumerator RetrySubmit() {
yield return new WaitForSeconds(_retrySeconds);
TryToSubmitScore();
}

void MatchComplete(){
SkillzCrossPlatform.ReturnToSkillz();
}

}

Fallback Score Reporting

Please Note:

ReportFinalScore has been deprecated and replaced by the DisplayTournamentResultsWithScore method.

The primary method for reporting a score to Skillz is through the methods defined above SubmitScore and ReturnToSkillz. However, DisplayTournamentResultsWithScore should always be implemented as a fallback in the event that the SubmitScore method fails. This best practice ensures your user’s scores will never be lost. This method submits the player score, then immediately returns the user to the Skillz UI.

Ensure that calling this method as fallback will prevent any pending/in-progress SubmitScore calls from triggering a new retry after the user returns to Skillz. If you do not do this, the pending retry may execute in a new game and you could end up submitting a previous game’s score.

MatchController.cs
// ...
void OnFailure(string reason) {
Debug.LogWarning("Fail: " + reason);
SkillzCrossPlatform.DisplayTournamentResultsWithScore(score);
}
// ...

Incomplete Matches

There are a couple ways to end a match prematurely. First, you can allow the user to quit the game and submit their current score, which gives them an opportunity to win with the score they have. Second, you can abort them from a match, which will result in a loss.

Depending on your specific gameplay, you will need to determine which method works best for you.

Aborting

Aborting a match is an alternative to reporting the final score. When a player aborts a match, they have forfeited it to the opponent.

SkillzCrossPlatform.AbortMatch();

Build and Run

Now it's time to test your game loop with Skillz. Please compile and run your game on a mobile device. If your game is made with Unity, you can use the Unity Companion to simulate your game loop with Skillz from the Unity editor. Once you have verified its workflow with Skillz works from the editor, follow the instructions on how to export and build your project for iOS or Android.

When you test your game loop, be sure to go to the Developer Console to have it report the user's score back and receive your second checkmark.