Sign In Register

How can we help you today?

Start a new topic

New Score Posted Message

Hello,

i want to notify my players when another player on the same challenge's leaderboard had posted a new score.


Can this be done with a script message listener?


My notification would be visualized only when the leaderboard is updated, which is controlled by the user.


Thanks


Hi Matteo,


You won't need a scriptMessage to do this. The ChallengeChangedMessage will update the users in a challenge when a score has been posted to a challenge leaderboard. The linked documentation page will also describe how the listener is set up. If you have any further questions then just let us know.



Regards,

Liam

Hello Liam,

this is what i am doing:

using GameSparks.Api.Messages;

then

 

    public void GetScoresUpdatedMessages()
    {
        ChallengeChangedMessage.Listener = (message) => 
        {
            var challenge = message.Challenge;
            var leaderboardData = message.LeaderboardData;
            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;
            string who = message.Who;
        };
    }

 I got an error related to the line:

 

            GSEnumerable<GSData> scriptData = message.ScriptData;

 saying:

Cannot implicitly convert GameSparks.Core.GSDATA to GameSparks.Core.GSEnumerable<GameSparks.Core.GSDATA>.


I heard of this error before, what you suggest?


Thanks

Update:

Commenting that line out solved the issue, but i am wondering why i get that error in the first place and how this could impact future implementation.


The Challenge Changed message is delivered promptly and in real-time though, which is great.


On a related question i would like to know how to access the nested type "ID"?


What i am looking for is the player id of the player that changed the challenge.


Thanks Again

Hi Matteo,


The error you were receiving was due to a type mismatch between the attribute you were accessing - ScriptData - and the variable you're trying to assign it to. You could resolve this by using


GSData scriptData = message.scriptData or var scriptData = message.scriptData


The message's 'who' field of the message contains the id of the player that changed the challenge.


Regards,

Vinnie

Hello Vinnie,

not sure how to access the id.


In fact "who" return the username of the player who changed the challenge, and not its unique player id.


I also tried message.LeaderboardData.UserId but this return an empty object.

Hi Matteo,


Yes, you're correct. The 'who' field returns the userName rather than the id. You can use this in conjunction with the challenge's 'accepted' array to obtain the user's Id. Try this out and let us know how it works for you.


Regards,

Vinnie

Thanks Vinnie,

that worked.


You can now close this ticket.


Thanks a lot,

Matteo


 

  ///FIND THE USER ID CORRESPONDING TO USER DISPLAY NAME
            foreach (var user in message.Challenge.Accepted)
            {
                if (message.Who == user.Name)
                {
                   ///Do something
                }
            }

 

Login to post a comment