Sign In Register

How can we help you today?

Start a new topic
Answered

Can't set message listener.

Hi!

I'm trying to set a message listener to the ChallengeStartedMessage listener, but it give me errors. 

Code (CSharp):

GameSparks.Api.Messages.ChallengeStartedMessage.Listener += (message) => {

  //Do something

}

The error: 

Code (csharp):

Unexpected symbol `+=' in class, struct, or interface member declaration

The API docs says that it should be setting like this: 

Code (CSharp):

ChallengeStartedMessage.Listener = (message) => {

  var challenge = message.Challenge;

  string messageId = message.MessageId;

  bool? notification = message.Notification;

  GSEnumerable<GSData> scriptData = message.ScriptData;

  string subTitle = message.SubTitle;

  string summary = message.Summary;

  string title = message.Title;

};

However, that doesn't work either, an throws this error instead:

Code (csharp):

Unexpected symbol `=' in class, struct, or interface member declaration


Best Answer

Hey Michael,


Try restructuring your code to something more like this: 




Chances are doing this will give you a more accurate conclusion as to where the error is occurring,

Hope this Helps,

-Tony


Answer

Hey Michael,


Try restructuring your code to something more like this: 




Chances are doing this will give you a more accurate conclusion as to where the error is occurring,

Hope this Helps,

-Tony

I got a different error when using the code that you have posted above :


Cannot implicitly convert type `GameSparks.Core.GSData' to `GameSparks.Core.GSEnumerable<GameSparks.Core.GSData>'

 

I bypassed this by commenting out "GSEnumerable<GSData> scriptData = message.ScriptData;".


This worked for me.

Login to post a comment