Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Problem with overwrite score at Steam Leaderboard

Discussion in 'Scripting' started by MG, Aug 15, 2017.

  1. MG

    MG

    Joined:
    Nov 10, 2012
    Posts:
    190
    I want to use the steam leaderboard. But it seems like only when I make new leaderboard, I can only write to it one time? Why is that?

    Here is the code for calling the upload score

    Code (CSharp):
    1. using UnityEngine;
    2. using Steamworks;
    3. using System.Collections;
    4. using System.Threading;
    5. public class SteamLeaderboard : MonoBehaviour {
    6.     private const string s_leaderboardName = "Highscore";
    7.     private const ELeaderboardUploadScoreMethod s_leaderboardMethod = ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodKeepBest;
    8.    
    9.  
    10.  
    11.     private static SteamLeaderboard_t s_currentLeaderboard;
    12.     private static bool s_initialized = false;
    13.     private static CallResult<LeaderboardFindResult_t> m_findResult = new CallResult<LeaderboardFindResult_t>();
    14.     private static CallResult<LeaderboardScoreUploaded_t> m_uploadResult = new CallResult<LeaderboardScoreUploaded_t>();
    15.    
    16.  
    17.     void Start()
    18.     {
    19.        
    20.         if (SteamManager.Initialized)
    21.         {
    22.             Init();
    23.             s_initialized = true;
    24.            
    25.             Invoke("Test123", 5);
    26.  
    27.         }
    28.        
    29.        
    30.     }
    31.  
    32.     void Test123()
    33.     {
    34.         UpdateScore(11236); // CHANGE SCORE VALUE HERE <---------------------------------------------
    35.     }
    36.    
    37.  
    38.  
    39.     public static void UpdateScore(int score)
    40.     {
    41.  
    42.         if (!s_initialized)
    43.         {
    44.             UnityEngine.Debug.Log("Can't upload to the leaderboard because isn't loadded yet");
    45.         }
    46.         else
    47.         {
    48.            
    49.             UnityEngine.Debug.Log("uploading score(" + score + ") to steam leaderboard(" + s_leaderboardName + ")");
    50.             SteamAPICall_t hSteamAPICall = SteamUserStats.UploadLeaderboardScore(s_currentLeaderboard, s_leaderboardMethod, score, null, 0);
    51.            
    52.             m_uploadResult.Set(hSteamAPICall, OnLeaderboardUploadResult);
    53.         }
    54.     }
    55.  
    56.     public static void Init()
    57.     {
    58.         SteamAPICall_t hSteamAPICall = SteamUserStats.FindLeaderboard(s_leaderboardName);
    59.         m_findResult.Set(hSteamAPICall, OnLeaderboardFindResult);
    60.         InitTimer();
    61.     }
    62.  
    63.     static private void OnLeaderboardFindResult(LeaderboardFindResult_t pCallback, bool failure)
    64.     {
    65.         UnityEngine.Debug.Log("STEAM LEADERBOARDS: Found - " + pCallback.m_bLeaderboardFound + " leaderboardID - " + pCallback.m_hSteamLeaderboard.m_SteamLeaderboard);
    66.         s_currentLeaderboard = pCallback.m_hSteamLeaderboard;
    67.         s_initialized = true;
    68.     }
    69.  
    70.     static private void OnLeaderboardUploadResult(LeaderboardScoreUploaded_t pCallback, bool failure)
    71.     {
    72.         UnityEngine.Debug.Log("STEAM LEADERBOARDS: failure - " + failure + " Completed - " + pCallback.m_bSuccess + " NewScore: " + pCallback.m_nGlobalRankNew + " Score " + pCallback.m_nScore + " HasChanged - " + pCallback.m_bScoreChanged);
    73.     }
    74.  
    75.  
    76.  
    77.  
    78.     private static Timer timer1;
    79.     public static void InitTimer()
    80.     {
    81.         timer1 = new Timer(timer1_Tick, null, 0, 1000);
    82.     }
    83.  
    84.     private static void timer1_Tick(object state)
    85.     {
    86.         SteamAPI.RunCallbacks();
    87.     }
    88. }
    89.  

    The currently written data is 1337, and no matter I set UploadScore to, it keeps coming with this messages:
    What am I doing wrong?
     
    CryT4x and hopetolive like this.
  2. MG

    MG

    Joined:
    Nov 10, 2012
    Posts:
    190
    No one?
     
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    Don't know. Don't develop for steam. What does their docs say? Are you sure there isn't a call to overwrite a leaderboard score? If you can write to it once, perhaps you have to use a different call or pass another parameter to have it use a different score after it gets the first score.
     
  4. B1ngo-

    B1ngo-

    Joined:
    Mar 10, 2018
    Posts:
    7
    Use
    Code (CSharp):
    1. private const ELeaderboardUploadScoreMethod s_leaderboardMethod = ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodForceUpdate;
    instead of
    Code (CSharp):
    1. private const ELeaderboardUploadScoreMethod s_leaderboardMethod = ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodKeepBest;
    I had the same problem. Now steam will overwrite the old value with the new one no matter what
     
    hopetolive and drew767 like this.
  5. lauhonyeung

    lauhonyeung

    Joined:
    Apr 29, 2017
    Posts:
    29
    meet the same problem, I use forceupdate and compare score by myself
     
  6. drew767

    drew767

    Joined:
    Jun 10, 2018
    Posts:
    2

    Thank you so so much!
     
  7. Garfeild

    Garfeild

    Joined:
    Oct 4, 2013
    Posts:
    1
    To anyone, who will be searching this: If you try to update score with higher value, make sure your leaderboard is set up to have sort method "Descending". For example, if old value = 100 and new value = 200. If sort method "Ascending", API doesn't update score.
     
    CryT4x and RedHillbilly like this.
  8. brinca

    brinca

    Joined:
    Mar 29, 2015
    Posts:
    33
    Be careful that there seems to be a bug where if you create a leaderboard with ascending order, and later change it to descending (and/or have it be "trusted" and then clear it), you'll need to recreate the leaderboard under a different name.

    I spent hours trying to figure out why it was not working, trying out different settings combinations, etc, only to find out that it worked perfectly when creating a different leaderboard from scratch.

    Also, don't bother filling in the community name when you create it, you'll need to edit the leaderboard and re-enter it anyway.
     
  9. simonrcodrington

    simonrcodrington

    Joined:
    Aug 25, 2018
    Posts:
    6
    In case anyone also stumbles on this, the above issue of creating an Ascending leader board and then switching it to Descending is still happening. I initial created mine with ascending an wondered why my calls to SteamUserStats.UploadLeaderboardScore kept returning a 0. Once I deleted the leader boards, set them up in the correct order and refreshed it all worked again.
     
  10. AlcoleponeHome

    AlcoleponeHome

    Joined:
    Jun 9, 2018
    Posts:
    47
    I have a issue with uploading to steam leaderboards, I wonder if it's the related. Often uploading a score works fine, but sometimes it fails. And from with in the editor debug information tells me the score went in fine and even the position in the leaderboard the score is. Steam just doesn't seem to have the score entry when looking at the app admin details. Any ideas?
     
  11. stevensuu

    stevensuu

    Joined:
    Oct 9, 2018
    Posts:
    1
    I have the same problem. I know it's been a while since you posted, but did you find a solution?
     
  12. migwellian

    migwellian

    Joined:
    Mar 20, 2018
    Posts:
    11