Character Stat API

This document describes how to use the standalone character stat javascript file to calculate character stats on your own website.

Step 1: Load a Character Profile

First, you need a character's stats to calculate! This document describes how to load a saved character profile from Ask Mr. Robot.

For reference: Mr. Robot's SWTOR Character Profile API Documentation
  1. Include the latest version of jQuery on your website.
  2. Use an ajax jsonp call to load a character profile (the ID is the GUID at the end of the URL when viewing the profile on askmrrobot.com):
function doit(profileId) {

    $.ajax({
        url: 'http://swtor.askmrrobot.com/api/character/v1/' + profileId,
        type: 'GET',
        dataType: 'jsonp',

        success: function (profile) {

            doSomethingWithProfile(profile);
        }
    });
}

Step 2: Get Stats!

Now that you have a profile, it's easy to get all of the stats for that character.
  1. Include Swtor.Calc.Standalone.js (available directly from the source code here), or you can link to the version on the askmrrobot cdn at http://static2.askmrrobot.com/swtor/calc.js
  2. Call the static getProfileStats method:
function getMeSomeStats(profile) {

    // this is all that you need to do! stats is an object with a property for every stat
    var stats = Tr.Swtor.Calc.getProfileStats(profile);
}
Note: check the Character Stat List for a description of the stats generated by getProfileStats.

Step 3: Test It

Here is a simple example of how to print out all of the stats so that you can view them for testing:
function printStats(stats) {

    // simple example for testing: print out all the stats to an html <div> element with ID 'panelDebug'
    var html = [];
    for (var stat in stats)
        html.push(stat + ': ' + stats[stat] + '<br/>');

    $('#panelDebug').html(html.join(''));
}
And the HTML:
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://static2.askmrrobot.com/swtor/calc.js"></script>
    <script src="my-js-that-does-the-stuff-above.js"></script>
</head>
<body>
    This panel is where we will print out the stats for testing:
    <div id="panelDebug"></div>
</body>
</html>
Note: This should work with any version of jQuery, but 1.9.1 was the latest version at the time this documentation was written.
Important Note! This example uses the calculation js on the askmrrobot cdn. If you are testing your own copy of the calculation javascript, make sure to use that one! Change the src of the script tag to point to your local js file.

Last edited Apr 24, 2013 at 6:35 PM by Yellowfive, version 6

Comments

No comments yet.