steam_upload_score_buffer

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

Syntax:

GML Code Example

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


Description

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:

  • "event_type" - This key will hold the value "leaderboard_upload" when triggered by this function

  • "lb_name" - This key holds the name of the leaderboard which was posted to

  • "success" - Will be 1 if the post succeeded, 0 failed

  • "updated" - Will be 1 if the leaderboard score was actually updated (ie: the new score was better) or 0 otherwise. Note that if the score is updated, the uploaded buffer data will not be added either.

  • "post_id" - This key should match the ID value returned by the upload call

  • "score" - This key holds the score which was posted

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:

GML Code Example

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;
       }
    buffer_delete(buff);
    }
 

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:

GML Code Example

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.





No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here