Sign In Register

How can we help you today?

Start a new topic
Answered

Simulate posting a score to leaderboard / Get rank in leaderboard without posting a score

 Hello,


Problem description:

  • Player should be able to play the game without logging into the facebook to authenticate himself.
  • I have a leaderboard and I'm posting score at the end of a level, only for user logged into facebook.
  • At the end of a level, in case of player being logged off I want to show him how many points he got and which rank he would get if he would be logged in.

I have a feeling that I'm missing something obvious here. I know that I can authenticate player device without connecting it to FB account to let him play the game and be able to display leaderboard. But can I simulate posting his score at the end of a level to get his rank? I don't want to save this score in the leaderboard if he don't log in into facebook.

I have thought about two workarounds but both of them seems to be wrong:

  1. Post score as a "device", get his rank and then ask to log in. If he logs in - save the score under his newly connected FB account. If player decides to not log into the FB - delete the "device score".
  2. Request all leaderboard entries (ugh!) and find manually (ugh again!) what is the possible rank of my player.

Is there a out-of-the-box solution for this kind of scenario that I'm missing?


Additional info:

I'm using Unity and creating builds for WebGL, iOS and Android.


Best Answer
Turned out there is a nearly out-of-the-box solution for that. I have missed a getRankForScore method in CloudCode. So if anyone ever need answer for above question here it is:
1. Check out how to use CloudCode here: https://docs.gamesparks.net/developer-portal/cloud-code/using-cloud-code
2. Set up an event with one NUMBER attribute, that will be the score you want to pass to getRankForScore
3. Edit CloudCode for that event (check #1 for How To Do).
Here's code that I have used:

var myScore = Spark.getData().simEScore; //That's score passed with the event
//We're using score passed in event to determine rank. "easyLead" is shortCode for my leaderboard
var rank = Spark.getLeaderboards().getLeaderboard("easyLead").getRankForScore({"score" : myScore}); 
Spark.setScriptData("rank", rank) //Rank is returned

 4. It's done, remember to update your custom GameSpark SDK in Unity.

 


Answer
Turned out there is a nearly out-of-the-box solution for that. I have missed a getRankForScore method in CloudCode. So if anyone ever need answer for above question here it is:
1. Check out how to use CloudCode here: https://docs.gamesparks.net/developer-portal/cloud-code/using-cloud-code
2. Set up an event with one NUMBER attribute, that will be the score you want to pass to getRankForScore
3. Edit CloudCode for that event (check #1 for How To Do).
Here's code that I have used:

var myScore = Spark.getData().simEScore; //That's score passed with the event
//We're using score passed in event to determine rank. "easyLead" is shortCode for my leaderboard
var rank = Spark.getLeaderboards().getLeaderboard("easyLead").getRankForScore({"score" : myScore}); 
Spark.setScriptData("rank", rank) //Rank is returned

 4. It's done, remember to update your custom GameSpark SDK in Unity.

 

Thanks for your contribution  Rafal. your answer is very well documented and intuitive. i'll make sure to link this thread to people with similar questions. 


Regards, Patrick. 


Login to post a comment