Sign In Register

How can we help you today?

Start a new topic
Answered

Blocking Example for GameSparksApi.mySyncLogEventRequest

Can you please provide an example on how to use the above request for blocking.

I am trying to call some information in from an event (call it "myevent") but when using myAsyncLogEventRequest it returns before the data is received, therefore is null. but when I attempt the above call in a blocking manner, it errors in unity stating "Cannot implicitly convert type `System.Collections.Generic.IDictionary<string,object>' to `GameSparks.GameSparksSender"


So far I have been unable to find any example on how to use this request in a blocking style forcing a wait until the data is returned before calling the completionfunction.

Current code is as follows:

 

	public IDictionary<string, object> getplayercharacter(string userid)
	{

		Debug.Log ("Player Data Requested");
		Dictionary<string, object> parameters = new Dictionary<string, object>();
		parameters.Add("UserID",userid);
		//GameSparksApi.mySyncLogEventRequest("GetPChar",parameters);
			GameSparksSender sender=GameSparksApi.mySyncLogEventRequest("GetPChar",parameters);
		//GameSparksApi.logEventRequest("GetPChar").sendAsync(delegate(IDictionary<string,object> response)
		sender.sendAsync(testcloudcodecompletion);
		return playerdata;
	}

 


Best Answer

Hi Jason


GameSparksSender has 2 methods for sending, sendAsync (which you are using now) is an asyncronous send, so will not block. You should use the send() method if you want to block.


Change the last 2 lines from :


sender.sendAsync(testcloudcodecompletion);

return playerdata;


To:


return sender.send();


That should do it.


Gabriel




Answer

Hi Jason


GameSparksSender has 2 methods for sending, sendAsync (which you are using now) is an asyncronous send, so will not block. You should use the send() method if you want to block.


Change the last 2 lines from :


sender.sendAsync(testcloudcodecompletion);

return playerdata;


To:


return sender.send();


That should do it.


Gabriel



Thank you. that done the trick.  So simple that I didn't see it :)

I was attempting to use sender.send(testcloudcodecompletion); which is where I went wrong.

Using your example it seems to be working using IDictionary<string,object> results=sender.send(); testcloudcodecompletion(results); 

now sending in the correct order (rather than reversing for some reason) and letting the first complete before doing the second.

Does the GameSparksSender class no longer exist? How can I make a call that blocks until the answer arrives?

Login to post a comment