Sign In Register

How can we help you today?

Start a new topic
Answered

ListMessageRequest foreach not working

I am trying to get a list of messages so that I can show the user at a later stage whether he has WON or LOST a challenge instead of showing it immediately when the listener gets called.

I have tried the following methods :


1. Code given under API reference:

new ListMessageRequest()
    .SetEntryCount(entryCount)
    .SetInclude(include)
    .SetOffset(offset)
    .Send((response) => {
        IList<GSData> messageList = response.MessageList; 
        GSData scriptData = response.ScriptData; 
    });

  IList<GSData> messageList = response.MessageList gives a compile error on UNITY

"Cannot implicitly convert type `GameSparks.Core.GSEnumerable<GameSparks.Core.GSData>' to `System.Collections.Generic.IList<GameSparks.Core.GSData>'. An explicit conversion exists (are you missing a cast?)"


2. Followed the answer given here :

Compile error goes away  but the following foreach loop does not get executed. Hence, the output is never obtained by me.

foreach (var c in response.MessageList)
          {
              messageList.Add(c.GetString("messageId"));
          }

If there is a better way to store the WIN/LOST message to show at a later instance, even that will do I suppose. 


Thanks in advance!


Best Answer

Hi Deftouch Design


That forum post is outdated.

The new way to loop the messageList is as follows

foreach (var c in response.BaseData.GetGSDataList("messageList")) 

{


}


Regards

Katie


Hi Deftouch Design


Have you tried calling ListMessageRequest in the Test Harness from the same player.

Does the Test Harness give you a list of messages?


Regards

Katie

It works on the test harness. In fact when I print response.JsonString to console in Unity it shows me the entire message correctly. The problem is only when I try to access the response.MessageList data via foreach loop.
Answer

Hi Deftouch Design


That forum post is outdated.

The new way to loop the messageList is as follows

foreach (var c in response.BaseData.GetGSDataList("messageList")) 

{


}


Regards

Katie

It is working now. Thanks you :)

Any idea when these updates will reflect in the documentation? Or is there any other source that I can refer to?
 

Login to post a comment