steam_upload_score

Upload a score to the Steam server.

Syntax:

GML Code Example

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:

  • "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

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

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


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:

GML Code Example

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:

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