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-
[Link]"></script> (or copy & paste the whole code as you like)
3. insert your game ID and private key into the static
properties [Link] and [Link] (located on top)
Testing
The library may not work properly on a local environment, because some browsers restrict
scripted HTTP requests from a [Link] 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.
[Link]
User Functions
[Link] (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
[Link]("Horsti", "myToken123", function(pResponse)
{
if([Link])
[Link]("Login successful");
});
[Link] ()
Requires no parameters and no communication with the server
[Link] (iUserID, pCallback)
number iUserID - Unique ID of an user
function pCallback - Callback function receiving a response object from the server
[Link](1, function(pResponse)
{
if(![Link]) return;
[Link]([Link][0].username + " - " + [Link][0].developer_description);
});
[Link] (sUserName, pCallback)
number sUserName - Unique name of an user
function pCallback - Callback function receiving a response object from the server
[Link]("CROS", function(pResponse)
{
if(![Link]) return;
[Link]([Link][0].username + " - " + [Link][0].developer_description);
});
[Link] (pCallback)
function pCallback - Callback function receiving a response object from the server
[Link](function(pResponse)
{
if(![Link]) return;
[Link]([Link][0].username + " - " + [Link][0].developer_description);
});
[Link]
Trophy Functions
[Link] (iTrophyID, pCallback)
number iTrophyID - Unique ID of a trophy
(optional) function pCallback - Callback function receiving a response object from the
server
[Link](1234, function(pResponse) {alert([Link]);});
[Link](1234);
[Link] (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
[Link](GJAPI.TROPHY_ALL, function(pResponse)
{
if(![Link]) return;
for(var i = 0; i < [Link]; ++i)
[Link]([Link][i].id + " - " + [Link][i].title);
});
[Link] (iTrophyID, pCallback)
number iTrophyID - Unique ID of a trophy
function pCallback - Callback function receiving a response object from the server
[Link](1234, function(pResponse)
{
if(![Link]) return;
[Link]([Link][0].id + " - " + [Link][0].title);
});
[Link]
Score Functions
[Link] (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
[Link](1234, 666, "666 Points", "valid entry", function(pResponse)
{alert([Link]);});
[Link](1234, 666, "666 Points");
[Link] (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
[Link](1234, 666, "666 Points", "Horsti", "valid entry", function(pResponse)
{alert([Link]);});
[Link](1234, 666, "666 Points", "Horsti");
[Link] (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
[Link](1234, GJAPI.SCORE_ALL, 5, function(pResponse)
{
if(![Link]) return;
for(var i = 0; i < [Link]; ++i)
{
var pScore = [Link][i];
[Link](([Link] ? [Link] : [Link]) + " - " + [Link]);
}
});
[Link]
Data Store Functions
GJAPI.DATA_STORE_USER = 0
GJAPI.DATA_STORE_GLOBAL = 1
[Link] (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
[Link](GJAPI.DATA_STORE_USER, "max-level", "5", function(pResponse)
{alert([Link]);});
[Link](GJAPI.DATA_STORE_GLOBAL, "players", "5");
[Link] (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
[Link](GJAPI.DATA_STORE_USER, "max-level", function(pResponse)
{
if([Link])
alert([Link]);
});
[Link] (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
[Link](GJAPI.DATA_STORE_USER, "max-level", "add", "1", function(pResponse)
{alert([Link]);});
[Link](GJAPI.DATA_STORE_GLOBAL, "players", "subtract", "1");
[Link] (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
[Link](GJAPI.DATA_STORE_USER, "max-level", function(pResponse)
{alert([Link]);});
[Link](GJAPI.DATA_STORE_GLOBAL, "players");
[Link] (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
[Link](GJAPI.DATA_STORE_USER, function(pResponse)
{
if(![Link]) return;
for(var i = 0; i < [Link]; ++i)
[Link]([Link][i].key);
});
Miscellaneous
Properties
Read-Only
boolean [Link] - User recognized and logged in
string [Link] - Current User Name
string [Link] - Current User Token
Read-and-Write
boolean [Link] - Set Session Active or Idle (default: true)
Other
string-map [Link] - Stores URL parameters (access with
[Link]["param"])
boolean [Link] - Embedded on Game Jolt
Custom Requests
[Link] (sUrl, bSendUser, pCallback)
[Link] (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
[Link]("/users/?user_id=1", GJAPI.SEND_GENERAL, function(pResponse)
{alert([Link]);});
__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("[Link] "", 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 ([Link]
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.