Sign In Register

How can we help you today?

Start a new topic
Answered

Cancel submitting a score

Hello,


In our leaderboards, we store an integer (the score) + two extra Strings, that contain data associated with the score (for example which character was used to achieve the score).


An issue we have is that even if we submit a lower score, it won't replace the score itself (that's logical), however it will replace the two strings with the new values. We would like this extra data in the leaderboards to only be replaced IF the new score is bigger (so if the leaderboard entry should be replaced).


Is there a way to do so ? 


If not, we are going for another solution : manually check the new score, compare it to the current score in the leaderboards and if the new score isn't bigger, immediately cancel the event (so we manually check if it's a new best score, and if not we try to abort).


However, doing so by putting code in our Event associated with the Leaderboard and using a Spark.exit() in case the new score is lower than the current best score in leaderboard doesn't work. The Spark.exit() is triggered, but GS proceeds to send the score nonetheless. Is that normal ? 


Best Answer

Hi,


Yes that should work fine. Another way to check a score would be to use the LogEventRequest Cloud Code script.

   

if(Spark.getData().eventKey == "myEvent"){
     //get the current lb entry and check against the incoming score. set scriptError and exit the script if required.
     Spark.setScriptError("Score", "Not Logged")
     Spark.exit()
    
 }

   

This would also allow you to prevent the score from being logged. It would also be a good way to filter out scores that are greater than a certain number. So if a users was logging scores that were showing signs of cheating or exploiting you could dismiss them so they won't end up in the leaderboard..


Regards,

Liam



I actually just found the issue, it was the type of attribute that was wrong. I was using "Used in script", while I should have used "Supplemental" so it wouldn't be updated at all in the leaderboard (except if there's a new highscore).

Answer

Hi,


Yes that should work fine. Another way to check a score would be to use the LogEventRequest Cloud Code script.

   

if(Spark.getData().eventKey == "myEvent"){
     //get the current lb entry and check against the incoming score. set scriptError and exit the script if required.
     Spark.setScriptError("Score", "Not Logged")
     Spark.exit()
    
 }

   

This would also allow you to prevent the score from being logged. It would also be a good way to filter out scores that are greater than a certain number. So if a users was logging scores that were showing signs of cheating or exploiting you could dismiss them so they won't end up in the leaderboard..


Regards,

Liam


That's actually what I was doing, without doing a setScriptError, and it did not abort the score submitting. Do you have to do a setScriptError (+ an exit()) to abort ? You can't just exit() ? I think that might have been my issue in this case :)

 No, you can just call Spark.exit() if you want.

This does not work.  I will raise a ticket with support as well.

On my CloudCode Script I have the following:

Spark.removeAllScriptData();
Spark.exit();

 There is no other code, and yet the scores are still being submitted and added to the leaderboard.

Hi All,


Just to clarify. The snippet above would go in the LogEventRequest Cloud Code script not the script for the Event that posts the score. If you navigate to Cloud Code>Requests>LogEventRequest on the Portal you can put it there and add your own check to validate the score and reject it if required.


Regards,

Liam

Login to post a comment