Understanding and Testing Challenges


Once a Challenge has been created, it needs to be tested to ensure it behaves the intended way. This tutorial will explain the best practices to follow so that a Challenge and the associated Players can be verified before it is integrated into the SDK.

Understanding Challenges

Before testing a Challenge, we need to fully understand all aspects of Challenges. This will help us to construct more effective Challenges to meet the needs of the application.

Challenge States

The Challenge states are as follows:

Challenge Transitions

Challenge transition from ISSUED state to RUNNING state:

Challenge transition from ISSUED state to EXPIRED state:

Challenge transition from ISSUED to WAITING:

Challenge transition from WAITING to RUNNING:

Challenge transition from RUNNING to COMPLETE:

Manipulating your Challenge through Cloud Code

By using Cloud Code through Challenge event logs, you can pass in the Challenge ID and access methods that affect that Challenge by using Spark.getChallenge(ChallengeID). Here's a list of some of the most useful things you can do:

Challenge Messaging

There are various messages that are associated with Challenges, some of which are shown in the following testing Challenge example. See the Message API>Multiplayer section of the API DOCUMENTATION for details.

Challenge Turn Taken Messages! Note that if you submit a LogChallengeEventRequest, then a ChallengeTurnTakenMessage will be automatically generated. This happens to ensure that you are notified if any change is effected by the request.

Testing your Challenge

To simulate multiple player interactions with a Challenge, we recommend that you open a number of tabs on your browser and use the Test Harness to simulate interaction from clients. For this test, open three tabs on your browser and authenticate a player on every tab.

1. Use you first authenticated player to submit a CreateChallengeRequest. For this example, we'll make it a public Challenge, which will start when the maximum numbers of players is met:

The first player receives a CreateChallengeResponse containing a challengeInstanceId.

2. Use your second authenticated player to submit a JoinChallengeRequest using this challengeInstanceID:

3. Switch back to the first authenticated player's tab. You'll see a message in yellow in the Test Harness Inspector - these messages can be caught by listeners - indicating that a player has joined the Challenge. The Challenge state will remain at ISSUED until the maximum number of players join the Challenge:

4. Finally, use your third authenticated player to submit a JoinChallengeRequest. After the third authenticated player joins the Challenge through the third tab, the other two players will receive a message - in yellow in the Inspector - indicating that another player has joined the Challenge and the state of the Challenge would change to RUNNING because the maximum number of players has been achieved:

Challenge Chat

You can use the challengeInstanceId to reference a Challenge and send a message to everyone involved. The message contains a string determined by the player and the rest is information about who sent the message and the Challenge details. Simply calling the request and supplying it with a message string will take care of distributing it to the rest of the players involved. Use Challenge message listeners to intercept these messages and extract the message string and who the message is from. You can then display the messages to players in-game.