Sign In Register

How can we help you today?

Start a new topic
Answered

Creating Challenges by code in Unity

Hello all. New GameSparks user here :) I'm making a game where players can post puzzles for other players to solve. When players start the game, they can either create a new puzzle or browse the list of puzzles posted by others, pick one and start solving it. All puzzles are publicly available and there's no limit on the number of players that can join an existing puzzle.

 

In order to implement the puzzles system, I'm thinking on leveraging the existing 'Challenges' available in the Multiplayer API. I've started by creating a small Unity test app in order to create a challenge by code and got the following error message:

 

GS: RECV:{"@class":".CreateChallengeResponse","error":{"challengeShortCode":"UNKNOWN"},"requestId":"636255407793346318_1"}
UnityEngine.Debug:Log(Object)
GameSparks.Platforms.<DebugMsg>c__AnonStorey0:<>m__0() (at Assets/GameSparks/Platforms/PlatformBase.cs:223)
GameSparks.Platforms.PlatformBase:Update() (at Assets/GameSparks/Platforms/PlatformBase.cs:89)

This is the code I'm using in order to create the challenge (notice that by the time this code gets reached, I've already authenticated using a valid username/password): 

 

var createChallengeRequest = new CreateChallengeRequest();
			createChallengeRequest.SetAccessType("PUBLIC").
				SetChallengeMessage("Optional challenge message.").
				SetChallengeShortCode("ChallengeShortCode01").
				SetEndTime(DateTime.MaxValue).
				Send((response) =>
				{
					if (response.HasErrors)
					{
						Debug.LogError("CreateChallengeRequest has errors.");
					}
					else
					{
						Debug.Log("CreateChallengeRequest successful! Instance ID: " + response.ChallengeInstanceId);
					}
				});

      

Any ideas on what am I doing wrong? Thanks in advance!


Best Answer

Hi Ignacio,


Have you set up the challenge details on the portal for  "ChallengeShortCode01"?


The shortCode is a challenge "type", not the instance of the challenge to be played. You are creating a challenge of type ChallengeShortCode01. You can set up the details for this in the Multiplayer tab on the portal.


-Pádraig


Answer

Hi Ignacio,


Have you set up the challenge details on the portal for  "ChallengeShortCode01"?


The shortCode is a challenge "type", not the instance of the challenge to be played. You are creating a challenge of type ChallengeShortCode01. You can set up the details for this in the Multiplayer tab on the portal.


-Pádraig


1 person likes this

Gotcha, that made the trick! Thank you very much for your swift reply.


--Ignacio

Login to post a comment