Sign In Register

How can we help you today?

Start a new topic
Answered

.LogChallengeEventResponse","error":{"scriptData":"UNKNOWN"} when trying to attach ScriptData to a Request

 (Using Unity)

The general question is how do I attach script data in client and access it in cloud code  ? Reverse scenario works (attaching scriptData in cloud code and accessing in client )

I am trying to attach a scriptData to my custom LogChallengeEventRequest_MYEVENT and if I attach it i get a response of :

  

GS: RECV:{"@class":".LogChallengeEventResponse","error":{"scriptData":"UNKNOWN"},"requestId":"635487375619308134_5","scriptData":null}

 


In the Challenge Event cloud code (not  LogEventRequest_MYEVENT) i only want to send some custom messages to the players with code like the following

var challenge = Spark.getChallenge(Spark.data.challengeId);

var playerIds = challenge.getAcceptedPlayerIds();
Spark.sendMessageByIdWithoutPush({"MYEVENT_ATTR":Spark.data.MYATTREVENT, 
                                  "CUSTOM_DATA": Spark.getScriptData("customData")}
                                  ,playerIds)

I am attaching the custom data with the following client code :

  

var reqData = new Dictionary<string,object> ();
reqData.Add ("CUSTOM_DATA", challengeId);
...
.SetScriptData(new GameSparks.Core.GSRequestData(reqData))

  


My CUSTOM_DATA is not an attribute of the event (I could make it and solve my problem) but I am asking how can One use script data from client to server?


Also a side question, is there a cloud code method that  does Spark.sendMessageByIdWithoutPush() without inserting the message into the playerMessages collections ? (so just as a means for sending volatile events from cloud to challenged clients)

 





Best Answer

 I had the same problem and had to change some things in the GameSparks API in the UnityProject:


In the file GameSparksSender.cs there's this block of code at the bottom of the file:

private IDictionary<String, object> scriptData = new Dictionary<string, object>();

public GameSparksSender addScriptData(String paramName, object paramValue)
{
    lock (scriptData)
    {
        if (!data.ContainsKey("scriptData"))
        {
            data.Add("scriptData", scriptData);
        }
    }
    scriptData.Add(paramName, paramValue);
    return this;
}

private GameSparks.Api.Requests.CustomRequest build()
{
    CustomRequest r = new CustomRequest(data).SetScriptData(new GameSparks.Core.GSRequestData(scriptData));
    return r;
}

 So the GameSparks API gives an empty Dictionary as scriptdata of your custom event call.
To prevent this from happening, I changed this block of code to this:

 

private IDictionary<String, object> scriptData = null;

public GameSparksSender addScriptData(String paramName, object paramValue)
{
    if (scriptData == null) scriptData = new Dictionary<String, object>();

    lock (scriptData)
    {
        if (!data.ContainsKey("scriptData"))
        {
            data.Add("scriptData", scriptData);
        }
    }
    scriptData.Add(paramName, paramValue);
    return this;
}

private GameSparks.Api.Requests.CustomRequest build()
{
    CustomRequest r = new CustomRequest(data);
    if (scriptData != null)
        r.SetScriptData(new GameSparks.Core.GSRequestData(scriptData));
    return r;
}

 

So now, when there's no scriptdata defined, scriptdata is null and won't be attached to the custom event call.


Hi Ovidiu, you'd have to set up an event with CUSTOM_DATA as an attribute as LogEvent/LogChallengeEvent requests do not accept arbitrary scriptData.


Messages will always go into playerMessages, there's no way to stop them form doing so.

Answer

 I had the same problem and had to change some things in the GameSparks API in the UnityProject:


In the file GameSparksSender.cs there's this block of code at the bottom of the file:

private IDictionary<String, object> scriptData = new Dictionary<string, object>();

public GameSparksSender addScriptData(String paramName, object paramValue)
{
    lock (scriptData)
    {
        if (!data.ContainsKey("scriptData"))
        {
            data.Add("scriptData", scriptData);
        }
    }
    scriptData.Add(paramName, paramValue);
    return this;
}

private GameSparks.Api.Requests.CustomRequest build()
{
    CustomRequest r = new CustomRequest(data).SetScriptData(new GameSparks.Core.GSRequestData(scriptData));
    return r;
}

 So the GameSparks API gives an empty Dictionary as scriptdata of your custom event call.
To prevent this from happening, I changed this block of code to this:

 

private IDictionary<String, object> scriptData = null;

public GameSparksSender addScriptData(String paramName, object paramValue)
{
    if (scriptData == null) scriptData = new Dictionary<String, object>();

    lock (scriptData)
    {
        if (!data.ContainsKey("scriptData"))
        {
            data.Add("scriptData", scriptData);
        }
    }
    scriptData.Add(paramName, paramValue);
    return this;
}

private GameSparks.Api.Requests.CustomRequest build()
{
    CustomRequest r = new CustomRequest(data);
    if (scriptData != null)
        r.SetScriptData(new GameSparks.Core.GSRequestData(scriptData));
    return r;
}

 

So now, when there's no scriptdata defined, scriptdata is null and won't be attached to the custom event call.

Login to post a comment