.LogChallengeEventResponse","error":{"scriptData":"UNKNOWN"} when trying to attach ScriptData to a Request
O
Ovidiu Buligan
started a topic
over 8 years ago
(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 :
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
F
Fries Boury
said
over 8 years ago
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.
F
Fries Boury
said
over 8 years ago
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.
Ovidiu Buligan
(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 :
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
I am attaching the custom data with the following client code :
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)
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:
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:
So now, when there's no scriptdata defined, scriptdata is null and won't be attached to the custom event call.
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
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.
Fries Boury
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:
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:
So now, when there's no scriptdata defined, scriptdata is null and won't be attached to the custom event call.
-
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 2487 topics