How to get challengeInstanceId in JoinedChallengeResponse?
A
Anatolii Landyshev
started a topic
almost 5 years ago
Hi. I'm developing a multiplayer soccer game with gamesparks. Challenge is a match of 2 players. Each player has a preset team of footballers, formation, tactics, etc. When 1st player creates a challenge his team is assigned to challenge.scriptData and challenge.privateData. I'm using Cloud Code for that. I wrote a handler for CreatedChallengeResponse. Now when 2nd player joins a challenge I want to add his team to challenge as well. I thought that I could just add handler for JoinedChallengeResponse. However today I found that there's no challengeInstanceId in JoinedChallengeResponse Spark.getData().
So I'd like to ask: is there any other way to do that? Or is it possible to get challenge we joined to somehow in JoinedChallengeResponse?
Thanks in advance.
Best Answer
A
Anatolii Landyshev
said
almost 5 years ago
I've just found another workaround. JoinChallengeRequest has challengeInstanceId property. So I add handler to JoinChallengeRequest with the following code line: Spark.setScriptData("challengeInstanceId", Spark.getData().challengeInstanceId);
Then in JoinChallengeResponse I use var challengeInstanceId = Spark.getScriptData("challengeInstanceId");
I've looked through those tutorials but haven't found an answer to my question. None of tutorials has a Cloud Code script for JoinedChallengeResponse. And those tutorials use few Cloud Code at all. They send data from clients.
In my case the problem is that there's no way to get challengeInstanceId in JoinedChallengeResponse cloud code handler. It's absent. I managed to implement my logic with AcceptChallengeResponse since it contains challengeInstanceId, but it works only for challenges player is invited to. If players wants to join PUBLIC challenge he cannot use AcceptChallengeResponse and here's where I encounter a problem.
I see the only workaround for that: when JoinedChallengeResponse is successful client should get challenge Id from JoinedChallengeResponse (it's available for client) and log special event to add his team to the challenge. However it looks like hack. I don't want to send extra events to server.
Best regards,
Anatolii
A
Anatolii Landyshev
said
almost 5 years ago
Answer
I've just found another workaround. JoinChallengeRequest has challengeInstanceId property. So I add handler to JoinChallengeRequest with the following code line: Spark.setScriptData("challengeInstanceId", Spark.getData().challengeInstanceId);
Then in JoinChallengeResponse I use var challengeInstanceId = Spark.getScriptData("challengeInstanceId");
Anatolii Landyshev
Hi. I'm developing a multiplayer soccer game with gamesparks. Challenge is a match of 2 players. Each player has a preset team of footballers, formation, tactics, etc.
When 1st player creates a challenge his team is assigned to challenge.scriptData and challenge.privateData. I'm using Cloud Code for that. I wrote a handler for CreatedChallengeResponse.
Now when 2nd player joins a challenge I want to add his team to challenge as well. I thought that I could just add handler for JoinedChallengeResponse.
However today I found that there's no challengeInstanceId in JoinedChallengeResponse Spark.getData().
So I'd like to ask: is there any other way to do that? Or is it possible to get challenge we joined to somehow in JoinedChallengeResponse?
Thanks in advance.
I've just found another workaround.
JoinChallengeRequest has challengeInstanceId property.
So I add handler to JoinChallengeRequest with the following code line:
Spark.setScriptData("challengeInstanceId", Spark.getData().challengeInstanceId);
Then in JoinChallengeResponse I use
var challengeInstanceId = Spark.getScriptData("challengeInstanceId");
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Anatolli,
There are several tutorials here that can help you match players together like that.
-how-to-find-challenges-for-a-player-based-on-their-eligibility
-setting-up-a-score-based-asynchronous-challenge
-unity-tutorials-challenges-part-1-introduction
Let us know if your still having any issues.
Thanks,
Oisin
Anatolii Landyshev
Oisin, thanks for quick response.
I've looked through those tutorials but haven't found an answer to my question. None of tutorials has a Cloud Code script for JoinedChallengeResponse.
And those tutorials use few Cloud Code at all. They send data from clients.
In my case the problem is that there's no way to get challengeInstanceId in JoinedChallengeResponse cloud code handler. It's absent.
I managed to implement my logic with AcceptChallengeResponse since it contains challengeInstanceId, but it works only for challenges player is invited to.
If players wants to join PUBLIC challenge he cannot use AcceptChallengeResponse and here's where I encounter a problem.
I see the only workaround for that: when JoinedChallengeResponse is successful client should get challenge Id from JoinedChallengeResponse (it's available for client) and log special event to add his team to the challenge. However it looks like hack. I don't want to send extra events to server.
Best regards,
Anatolii
Anatolii Landyshev
I've just found another workaround.
JoinChallengeRequest has challengeInstanceId property.
So I add handler to JoinChallengeRequest with the following code line:
Spark.setScriptData("challengeInstanceId", Spark.getData().challengeInstanceId);
Then in JoinChallengeResponse I use
var challengeInstanceId = Spark.getScriptData("challengeInstanceId");
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2485 topics