Custom Score For Leaderboard

Discussion in 'How Can I...?' started by dennisms, Dec 3, 2020.

  1. dennisms

    dennisms Boxer

    Joined:
    Jan 18, 2020
    Messages:
    22
    Likes Received:
    3
    Hey guys!

    I am trying to create a custom score system to be registered with the leaderboard.

    I use this.scene().setScorePoint(bestScore) function to set the custom score, but the score doesn't update for the live leaderboard.

    Does this function (setScorePoint()) actually saves the score for the leaderboard?

    Thank you very much!
     
  2. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    set
    Yes setScorePoint or more specificly this.scene().setScorePoint(value) sets both global and local score points into the memory the difference between local and global is that global poits are saved and local points are not saved after closing and opening the app.
     
    dennisms likes this.
  3. dennisms

    dennisms Boxer

    Joined:
    Jan 18, 2020
    Messages:
    22
    Likes Received:
    3
    Hello!

    Does the this.scene().addScorePoint(amount) function differ from this.scene().setScorePoint(value) regarding the registration of score on the leaderboard?

    I am saving a score from a global variable using this.scene().setScorePoint(value), but the score doesn't register on the leaderboard!

    Thank you!
     
  4. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Alright so it seems that I wasn't that clear on the above message so let me try again. Everything is related to the "Score Type" option in Project settings. Now that dropdown contains the following options:
    • Distance - Used to show the best distance reached on a specific world
    • Coins Collected - Used to show the collected coins from a specific world
      Code:
      this.scene().bestCoins();
    • Points Collected - Used to show the collected points from a specific world
      Code:
      this.scene().bestPoints();
    • Global Distance - Used to show the best Global distance from your entire game. (Highest distance reached ever)
    • Global Coins - Used to show the best Global Coins from the entire game
      Code:
      this.scene().bestGlobalCoins();
    • Global Points - Used to show the best Global Points from the entire game
      Code:
      this.scene().bestGlobalPoints();
    [​IMG]

    Now let's see what options we have for both Coins and Points system so far:
    For Score we have:
    Code:
       this.scene().addScorePoint(value); // adds additional value amount of points (100+100+100 etc)
        this.scene().setScorePoint(value); // set the value of points to the specified value (100) 
    For Points we have:
    Code:
        this.scene().addScoreCoin(value); // adds additional value amount of coins (100+100+100 etc)
    

    Now based on what I write above you can decide what option you want to use on Score type (Use Coins Collected for world's best coins or Global Coins for overall highscore)

    TO understand how the Add and set works for Points and Score I've prepared a small snippet code to get a general idea on how they work. As a side note you will see / have a way to reset the scores by using reset built in methods:
    Code:
        this.scene().resetPoints();
        this.scene().resetCoins();
        this.scene().resetGlobalPoints();
        this.scene().resetGlobalCoins();
    Code used to understand this process:
    [​IMG]

    To understand how everything needs to be setup for Android please follow the below video made by @Smart Penguins
     
    Last edited: Dec 5, 2020
  5. dennisms

    dennisms Boxer

    Joined:
    Jan 18, 2020
    Messages:
    22
    Likes Received:
    3
    Hello

    If i use this.scene().setScorePoint(value) to save a specific score to leaderboard it doesn't get saved.

    It seems that only this.scene()[callNameAdd](amount) records the score to the leaderboard
    callNameAdd = 'addScore' + (pc == 'kCoins' ? 'Coin' : 'Point')
     
  6. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    It is the same thing, it should work the same for both scenarios. The above code will trigger this.scene().setScorePoints(value) or this.scene().setScoreCoin(value) based on your selection (from the dropdown).
     
    Last edited: Dec 6, 2020
    dennisms likes this.
  7. dennisms

    dennisms Boxer

    Joined:
    Jan 18, 2020
    Messages:
    22
    Likes Received:
    3
    Hello

    I have this counter in my game and i want to save the value of the counter to the leaderboard using this.scene().setScorePoint(counter) when the game is over. But the score don't get updated on the leaderboard.

    Thanks!
     
  8. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    This might be due to the fact that the score is not updated since an event jump pauses the world or scene. Try to add a delay before you jump to game over screen.
     
    dennisms likes this.
  9. dennisms

    dennisms Boxer

    Joined:
    Jan 18, 2020
    Messages:
    22
    Likes Received:
    3
    Yup! That was the issue!
    Thank you very much!
     

Share This Page