Upload a score to the Steam server along with a small packet of additional data.


steam_upload_score_buffer(lb_name, score, buffer);

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).
buffer The ID of the buffer to attach.

Returns: Real


This function will send a score to the given leaderboard along with a data package created from a buffer. The buffer should be no more than 256 bytes in size - anything beyond that will be chopped off - and can contain any data you require. The score to be uploaded should be 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:

Note that if the function when downloading the leaderboard, the "entries" key of the async_load map will now have a "data" key so you can retrieve the uploaded data buffer (see the Steam Event extended code example for further details).

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, with a buffer being created to hold a string telling us which level the score was uploaded from:

if (hp <= 0)
   var buff = buffer_create(256, buffer_fixed, 1 );    buffer_write(buff, buffer_string, "Uploaded on level " + string(global.Level));    upload_ID = steam_upload_score("Game Scores", score, buff);
   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... Also note that we immediately delete the buffer, since it is no longer required for the function. 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");
         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.

Back: Steam API
Next: steam_download_scores
© Copyright YoYo Games Ltd. 2015 All Rights Reserved