0% found this document useful (0 votes)
80 views8 pages

Game Jolt Separate Library: Installation

The document describes how to install and use the Game Jolt API library. It explains how to add the library files, initialize it with a game ID and key, and covers various user, trophy, score and data functions. It also lists some properties and methods for custom requests.

Uploaded by

CDDani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views8 pages

Game Jolt Separate Library: Installation

The document describes how to install and use the Game Jolt API library. It explains how to add the library files, initialize it with a game ID and key, and covers various user, trophy, score and data functions. It also lists some properties and methods for custom requests.

Uploaded by

CDDani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Installation

The current library is available from Game Jolt and contains all necessary files.
It is made for browser-based JavaScript applications - for Unity please look at a separate library.

To install the library into your game you have to

1. add the normal or minified JS-file to your project directory

2. include (link) the library into your main HTML-file with  <script src="gj-js-
api.js"></script>  (or copy & paste the whole code as you like)

3. insert your game ID and private key into the static


properties GJAPI.iGameID and GJAPI.sGameKey (located on top)

Testing

The library may not work properly on a local environment, because some browsers restrict
scripted HTTP requests from a file:/// path.
In this case you have to upload the project to Game Jolt, setup a local server process, or change
the (browser-specific) configuration, to test it.

Still, to test the implementation offline, add  ?


gjapi_username=NAME&gjapi_token=TOKEN  (replaced with valid credentials) to your URL.
If everything is fine, the library should automatically start a session, visible on the user-profile.

https://gamejolt.com/api/doc/game/users/

User Functions

GJAPI.UserLoginManual (sUserName, sUserToken, pCallback)

 string sUserName - Login name of an user

 string sUserToken - Token of that user (not the password)

 (optional) function pCallback - Callback function receiving a response object from the


server

GJAPI.UserLoginManual("Horsti", "myToken123", function(pResponse)


{
    if(pResponse.success)
        console.info("Login successful");
});
GJAPI.UserLogout ()

 Requires no parameters and no communication with the server

GJAPI.UserFetchID (iUserID, pCallback)

 number iUserID - Unique ID of an user

 function pCallback - Callback function receiving a response object from the server

GJAPI.UserFetchID(1, function(pResponse)
{
    if(!pResponse.users) return;
    console.info(pResponse.users[0].username + " - " + pResponse.users[0].developer_description);
});

GJAPI.UserFetchName (sUserName, pCallback)

 number sUserName - Unique name of an user

 function pCallback - Callback function receiving a response object from the server

GJAPI.UserFetchName("CROS", function(pResponse)
{
    if(!pResponse.users) return;
    console.info(pResponse.users[0].username + " - " + pResponse.users[0].developer_description);
});

GJAPI.UserFetchCurrent (pCallback)

 function pCallback - Callback function receiving a response object from the server

GJAPI.UserFetchCurrent(function(pResponse)
{
    if(!pResponse.users) return;
    console.info(pResponse.users[0].username + " - " + pResponse.users[0].developer_description);
});

https://gamejolt.com/api/doc/game/trophies/

Trophy Functions

GJAPI.TrophyAchieve (iTrophyID, pCallback)

 number iTrophyID - Unique ID of a trophy


 (optional) function pCallback - Callback function receiving a response object from the
server

GJAPI.TrophyAchieve(1234, function(pResponse) {alert(pResponse.message);});


GJAPI.TrophyAchieve(1234);

GJAPI.TrophyFetch (iAchieved, pCallback)

 number iAchieved - Status of the requested trophies (GJAPI.TROPHY_*)

 function pCallback - Callback function receiving a response object from the server

GJAPI.TROPHY_ONLY_ACHIEVED = 1
GJAPI.TROPHY_ONLY_NOTACHIEVED = -1
GJAPI.TROPHY_ALL = 0

GJAPI.TrophyFetch(GJAPI.TROPHY_ALL, function(pResponse)
{
    if(!pResponse.trophies) return;

    for(var i = 0; i < pResponse.trophies.length; ++i)


        console.info(pResponse.trophies[i].id + " - " + pResponse.trophies[i].title);
});

GJAPI.TrophyFetchSingle (iTrophyID, pCallback)

 number iTrophyID - Unique ID of a trophy

 function pCallback - Callback function receiving a response object from the server

GJAPI.TrophyFetchSingle(1234, function(pResponse)
{
    if(!pResponse.trophies) return;
    console.info(pResponse.trophies[0].id + " - " + pResponse.trophies[0].title);
});

https://gamejolt.com/api/doc/game/scores/

Score Functions

GJAPI.ScoreAdd (iScoreTableID, iScoreValue, sScoreText, sExtraData, pCallback)

 number iScoreTableID - Unique ID of a score table (0 = primary score table)

 number iScoreValue - Numerical sort value of the score

 string sScoreText - Score string

 (optional) string sExtraData - Extra data associated with the score


 (optional) function pCallback - Callback function receiving a response object from the
server

GJAPI.ScoreAdd(1234, 666, "666 Points", "valid entry", function(pResponse)


{alert(pResponse.message);});
GJAPI.ScoreAdd(1234, 666, "666 Points");

GJAPI.ScoreAddGuest (iScoreTableID, iScoreValue, sScoreText, sGuestName, sExtraData,


pCallback)

 number iScoreTableID - Unique ID of a score table (0 = primary score table)

 number iScoreValue - Numerical sort value of the score

 string sScoreText - Score string

 string sGuestName - Name of a guest user (null = logged in user)

 (optional) string sExtraData - Extra data associated with the score

 (optional) function pCallback - Callback function receiving a response object from the


server

GJAPI.ScoreAddGuest(1234, 666, "666 Points", "Horsti", "valid entry", function(pResponse)


{alert(pResponse.message);});
GJAPI.ScoreAddGuest(1234, 666, "666 Points", "Horsti");

GJAPI.ScoreFetch (iScoreTableID, bOnlyUser, iLimit, pCallback)

 number iScoreTableID - Unique ID of a score table (0 = primary score table)

 boolean bOnlyUser - Fetch only score entries from the current main user (GJAPI.SCORE_*)

 number iLimit - Max number of fetched score entries

 function pCallback - Callback function receiving a response object from the server

GJAPI.SCORE_ONLY_USER = true
GJAPI.SCORE_ALL = false

GJAPI.ScoreFetch(1234, GJAPI.SCORE_ALL, 5, function(pResponse)


{
    if(!pResponse.scores) return;

    for(var i = 0; i < pResponse.scores.length; ++i)


    {
        var pScore = pResponse.scores[i];
        console.info((pScore.user ? pScore.user : pScore.guest) + " - " + pScore.score);
    }
});

https://gamejolt.com/api/doc/game/data-store/

Data Store Functions

GJAPI.DATA_STORE_USER = 0
GJAPI.DATA_STORE_GLOBAL = 1

GJAPI.DataStoreSet (iStore, sKey, sData, pCallback)

 number iStore - Scope of the operation, global or per user (GJAPI.DATA_STORE_*)

 string sKey - The key of the data item to set

 string sData - The data to set

 (optional) function pCallback - Callback function receiving a response object from the


server

GJAPI.DataStoreSet(GJAPI.DATA_STORE_USER, "max-level", "5", function(pResponse)


{alert(pResponse.message);});
GJAPI.DataStoreSet(GJAPI.DATA_STORE_GLOBAL, "players", "5");

GJAPI.DataStoreFetch (iStore, sKey, pCallback)

 number iStore - Scope of the operation, global or per user (GJAPI.DATA_STORE_*)

 string sKey - The key of the data item to fetch

 function pCallback - Callback function receiving a response object from the server

GJAPI.DataStoreFetch(GJAPI.DATA_STORE_USER, "max-level", function(pResponse)


{
    if(pResponse.success)
        alert(pResponse.data);
});

GJAPI.DataStoreUpdate (iStore, sKey, sOperation, sValue, pCallback)

 number iStore - Scope of the operation, global or per user (GJAPI.DATA_STORE_*)

 string sKey - The key of the data item to update

 string sOperation - The operation to perform (add, subtract, multiply, divide, append,


prepend)
 string sValue - The value to work

 (optional) function pCallback - Callback function receiving a response object from the


server

GJAPI.DataStoreUpdate(GJAPI.DATA_STORE_USER, "max-level", "add", "1", function(pResponse)


{alert(pResponse.message);});
GJAPI.DataStoreUpdate(GJAPI.DATA_STORE_GLOBAL, "players", "subtract", "1");

GJAPI.DataStoreRemove (iStore, sKey, pCallback)

 number iStore - Scope of the operation, global or per user (GJAPI.DATA_STORE_*)

 string sKey - The key of the data item to remove

 (optional) function pCallback - Callback function receiving a response object from the


server

GJAPI.DataStoreRemove(GJAPI.DATA_STORE_USER, "max-level", function(pResponse)


{alert(pResponse.message);});
GJAPI.DataStoreRemove(GJAPI.DATA_STORE_GLOBAL, "players");

GJAPI.DataStoreGetKeys (iStore, pCallback)

 number iStore - Scope of the operation, global or per user (GJAPI.DATA_STORE_*)

 function pCallback - Callback function receiving a response object from the server

GJAPI.DataStoreGetKeys(GJAPI.DATA_STORE_USER, function(pResponse)
{
    if(!pResponse.keys) return;

    for(var i = 0; i < pResponse.keys.length; ++i)


        console.info(pResponse.keys[i].key);
});

Miscellaneous

Properties

Read-Only

 boolean GJAPI.bActive - User recognized and logged in

 string GJAPI.sUserName - Current User Name

 string GJAPI.sUserToken - Current User Token

Read-and-Write
 boolean GJAPI.bSessionActive - Set Session Active or Idle (default: true)

Other

 string-map GJAPI.asQueryParam - Stores URL parameters (access with


GJAPI.asQueryParam["param"])

 boolean GJAPI.bOnGJ - Embedded on Game Jolt

Custom Requests

GJAPI.SendRequest (sUrl, bSendUser, pCallback)


GJAPI.SendRequestEx (sUrl, bSendUser, sFormat, sBodyData, pCallback)

 string sUrl - Relative API request string

 boolean bSendUser - Automatically include username and token to the request


(GJAPI.SEND_*)

 string sFormat - Data return format (default: "json")

 string sBodyData - The content of the body to be sent (default: "")

 (optional) function pCallback - Callback function receiving a response object from the


server

GJAPI.SEND_USER = true
GJAPI.SEND_GENERAL = false

GJAPI.SendRequest("/users/?user_id=1", GJAPI.SEND_GENERAL, function(pResponse)


{alert(pResponse.message);});

__CreateAjax (sUrl, sBodyData, pCallback)

 string sUrl - Custom Ajax request string

 (optional) string sBodyData - The content of the body to be sent

 (optional) function pCallback - Callback function receiving a response object from the


server

__CreateAjax("https://gamejolt.com/img/no-avatar-1.png", "", function(sDataString)


{alert(sDataString);});

Activity Log

The library logs useful information into the JavaScript console of your browser,
consisting of some basic information, generated requests, and returned data from the server.
Credits

Author: Martin Mauersics
Special Thanks to: David "CROS" DeCarmine, Bruno Assarisse, Jani "JNyknn" Nykänen, Travis
"Clonze" Miller, Garden Variety
This is a 3rd party software which is not directly affiliated with Game Jolt or Lucent Web Creative,
LLC.

Additional Libraries

JavaScript implementation of the RSA Data Security, Inc. MD5 Message Digest Algorithm by Paul
Johnston (http://pajhome.org.uk/)

Software License

Copyright (c) 2014-2015 Martin Mauersics

This software is provided 'as-is', without any express or implied


warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,


including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source


distribution.

You might also like