Sign In Register

How can we help you today?

Start a new topic
Answered

LogEventRequest reports Error but ScriptData has been updated

Good Evening,


Have just started to use your Service for a Turn Based Mutliplayer Game, and while I'm slowly getting my head around Matches and Challenges could use some extra help with what I've found.


Before the AcceptChallengeRequest is fired I need to upload a scriptdata variable called seedToken do once AcceptChallengeRequest is fired each side can generate the level using this seedToken.


I've used the follow Support ticket https://support.gamesparks.net/support/discussions/topics/1000050081 and set up a LogEventRequest on the back of a CreateChallengeRequest response to send the seedToken, my code looks like this:

 

    public void ChallengePlayer(List<string> PlayerIDs)
    {
        new CreateChallengeRequest().SetChallengeShortCode("ZombieTurn")
            .SetUsersToChallenge(PlayerIDs)
            .SetEndTime(System.DateTime.Today.AddDays(1))
            .Send((response) =>
            {
                if (response.HasErrors)
                {
                    Debug.Log(response.Errors);
                }
                else
                {
                    Debug.Log("Challenge Sent!");
                    Debug.Log(response.ChallengeInstanceId);

                    new LogEventRequest().SetEventAttribute("challengeInstanceId", response.ChallengeInstanceId)
                    .SetEventAttribute("seedToken", "TESTING")
                    .SetEventKey("takeTurn")
                    .Send((SeedResponse) =>
                    {
                        if (SeedResponse.HasErrors)
                        {
                            Debug.Log(SeedResponse.Errors);
                        }
                        else
                        {
                            Debug.Log("Unable to send seed to GameSparks!");
                        }
                    });
                    
                }
            });
    }

 My server side code attached to LogEventRequesr is:

 

var ChallengeID = Spark.getData().challengeInstanceId;
var seedToken  =Spark.getData().seedToken;

var thisChallenge = Spark.getChallenge(Spark.getData().challengeInstanceId);
thisChallenge.setScriptData("seedToken", Spark.getData().seedToken);

 

The issue is that the response I receive back in unity is:

 

GS: RECV:{"@class":".LogEventResponse","error":{"challengeInstanceId":"UNKNOWN","seedToken":"UNKNOWN"},"requestId":"635822521456723557_3","scriptData":null}
UnityEngine.Debug:Log(Object)
GameSparks.Platforms.<DebugMsg>c__AnonStorey6:<>m__4() (at Assets/GameSparks/Platforms/PlatformBase.cs:133)
GameSparks.Platforms.PlatformBase:Update() (at Assets/GameSparks/Platforms/PlatformBase.cs:64)

 

I don't understand why Unity is reporting an Error when on the ChallengeAccepted I can see my seedToken in ScriptData.


Any help would be great.

Thanks.



Best Answer
Hi Adam

LogEventRequest is used to call a custom event,In your case calling the takeTurn event.
So the takeTurn event need to have the cloud code logic in it. You will also need to give takeTurn the attributes you want passed you can set these up in the edit event section.
In cloud code you can read in the attributes using
var seedToken = Spark.getData().seedToken;
Once you do the logic you want you can return the attributes if you changed the values using
Spark.setScriptData("seedToken", seedToken);

To test in Test Harness go to LogEvent and run the takeTurn event.

Thanks
Katie

 


Hi Adam

To get the challenge ID use Spark.data.challengeId, If you remove () after data  you will get the challengeId and seedToken
The test harness is very handy for testing sever side code and will help you know if the error is in cloud code or in unity.

Thanks
Katie

 

Thanks for the response Katie.


I've updated my CloudCode and that is referencing objects correctly now.


But I still get a error response: 

{
 "@class": ".LogEventResponse",
 "error": {
  "challengeInstanceId": "UNKNOWN",
  "seedToken": "UNKNOWN"
 },
 "scriptData": null
}


I get this when sending the following through the Test Harness:

 

{
	"@class":".LogEventRequest",
	"challengeInstanceId":"563bc2c1e4b07354d4a060b0",
	"seedToken":"584591467",
	"eventKey":"takeTurn"
}

 

Thanks for your help.

Answer
Hi Adam

LogEventRequest is used to call a custom event,In your case calling the takeTurn event.
So the takeTurn event need to have the cloud code logic in it. You will also need to give takeTurn the attributes you want passed you can set these up in the edit event section.
In cloud code you can read in the attributes using
var seedToken = Spark.getData().seedToken;
Once you do the logic you want you can return the attributes if you changed the values using
Spark.setScriptData("seedToken", seedToken);

To test in Test Harness go to LogEvent and run the takeTurn event.

Thanks
Katie

 

Login to post a comment