Sign In Register

How can we help you today?

Start a new topic
Answered

Messages lost

Sometime, at least on IOS, my unity client get unable to receive any messages from GameSparks. I'm still able to receive response to my requests, and the active player is marked as online in its player record (as seen on the NoSQL portal). Also the messages are not kept and sent afterward when I'm logging the player on the test harness (where the messages are always correctly received).


My game need players to quite often reliably receive messages from the server and I'm at a lost to find the solution to this problem. Any way to figure it out would be helpful.


I use Spark.sendMessageByIdWithoutPush()

I do not use the challenge functionalities.


Best Answer

I think I found my problem.

I had, quite some time ago, followed THIS to create my message listener:

 

void Start(){
GameSparksApi.GameSparksMessageReceived  += HandleGameSparksMessageReceived;

}

 

void HandleGameSparksMessageReceived (object sender, GameSparksMessageReceivedEventArgs e)

{

Debug.Log(“MSG” + e.Message);

}

But I had forgot to had this to the provided code:

 

void OnDestroy() {
		GameSparksApi.GameSparksMessageReceived -= HandleGameSparksMessageReceived;
	}

All was well until i reloaded the scene and screwed the delegate. I was rarely reloading the scene (only to change the active language) so it was usually no problem and I had not noticed the problem as everything seemed nice at first glance. I admittedly have not much experience with delegates but the error messages seemed to come from everywhere apart from this. 

I hope this will help someone else.



Hi Gabriel. Do you already have a live version out? If yes, have you checked preview build in GameSparksSettings in Unity when you tested the method?

I don't have any live snapshot yet and PreviewBuild and DebugBuild is checked in GameSparksSettings. Also I don't think I ever missed a message when playing inside the unity editor. It is only happening on my testing iPad (I haven't tested my game on android yet). 

I use this to read messages:

  

void Start () {
	GameSparksApi.GameSparksMessageReceived += HandleGameSparksMessageReceived;
}

void HandleGameSparksMessageReceived (object sender, GameSparksMessageReceivedEventArgs e) {
	GSData messageData = (GSData) e.Message["data"];

	{...}

}

  

Often, everything is working fine on my iOS device and then it suddenly stop interpreting messages.


I've tested on the iPhone, and it works. Your Unity code is correct. Your cloud code may be the problem. It's noteworthy that Spark.getPlayerIds() always returns an empty array (at least for me). This however works.

Spark.sendMessageWithoutPush({"alert" : "The time in ms is "+Date.now()}, new Array(Spark.getPlayer()));

You can get by sending messages to all players by doing something like this

var nameListCollection = Spark.runtimeCollection("playerDirectory").find();
var nameList = new Array();

while(nameListCollection.hasNext())
{
    var myPlayer = nameListCollection.next();
    nameList.push(Spark.loadPlayer(myPlayer.playerId));
}

Spark.sendMessage({"alert" : "You've just won a car!"}, nameList);

 

 Revision: sendMessage can be replaced with sendMessageWithoutPush and it would work just the same.

Answer

I think I found my problem.

I had, quite some time ago, followed THIS to create my message listener:

 

void Start(){
GameSparksApi.GameSparksMessageReceived  += HandleGameSparksMessageReceived;

}

 

void HandleGameSparksMessageReceived (object sender, GameSparksMessageReceivedEventArgs e)

{

Debug.Log(“MSG” + e.Message);

}

But I had forgot to had this to the provided code:

 

void OnDestroy() {
		GameSparksApi.GameSparksMessageReceived -= HandleGameSparksMessageReceived;
	}

All was well until i reloaded the scene and screwed the delegate. I was rarely reloading the scene (only to change the active language) so it was usually no problem and I had not noticed the problem as everything seemed nice at first glance. I admittedly have not much experience with delegates but the error messages seemed to come from everywhere apart from this. 

I hope this will help someone else.