steam_upload_score

Syntax:

steam_upload_score(lb_name, score);


Argument Description
lb_name The name of the leaderboard that you are uploading the scores to (a string).
score The score to upload (a real number).


Returns: Real


Description

This function will send a score to the given leaderboard. The score to be uploaded is a real number, and the leaderboard name is a string that was defined when you created the leaderboard using the function steam_create_leaderboard. If the function fails, it will return a value of -1, while a successful post will return a unique ID for the upload and trigger an asynchronous Steam Event. This event will create a ds_map in the built in variable async_load with the following key/value pairs:


Extended Example:

In this example, we first upload a score and then parse the async_load map returned if successful. The code below shows a typical example for uploading:

if (hp <= 0)
   {
   upload_ID = steam_upload_score("Game Scores", score);
   if (!upload_ID)
      {
      alarm[0] = room_speed;
      }
   }

Note that we have set an alarm if the call fails. This would be used to try the upload again at a later time and you can add extra code there to retry the upload or to save the score to a text file should it continue to fail, etc... We now add the following into the Steam async event for the instance controlling the scores:

var type = ds_map_find_value(async_load, "event_type");
if (type == "leaderboard_upload")
   {
   var lb_ID = ds_map_find_value(async_load, "post_id");
   if lb_ID == upload_ID
      {
      var lb_name = ds_map_find_value(async_load, "lb_name");
      var lb_done = ds_map_find_value(async_load, "success");
      var lb_score = ds_map_find_value(async_load, "score");
      var lb_updated = ds_map_find_value(async_load, "updated");
      show_debug_message("leaderboard post id:" + string(lb_ID) + " to lb:" + string(lb_name) + " with score:" + string(lb_score) + " updated=" + string(lb_updated));
      if (lb_done)
         {
         show_debug_message("- Succeeded");
         }
      else
         {
         show_debug_message("- Failed");
         }
      }
   }

in the example we are simply outputting the return values to the compiler window as debug messages, but you can use this event to deal with the information in any way you choose.