Skip to content

Trophies

Francisco Dias edited this page Jan 30, 2023 · 1 revision

Back To Top

Feed into your player base's hunger for trophy hunting. Trophies will sync to their Game Jolt profile for all to see as badges of honor.

Functions

The following functions are provided for working with trophies:

Structs

Extra details on structs that are returned as trophy fetching results:




Back To Top

This function fetches a trophy data (see TrophyData). This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_Trophies_Fetch(trophy_id, [callback_success], [callback_failed])
Argument Type Description
trophy_id real The trophy identifier
callback_success function The callback function executed if the request succeeds (a TrophyData struct is passed as argument) ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_Trophies_Fetch(myTropyID,
    function(_trophyData)
    {
        var _id = _trophyData.id;
        var _title = _trophyData.title;
        var _description = _trophyData.description;
        var _difficulty = _trophyData.difficulty;
        var _image_url = _trophyData.image_url;
        var _achieved = _trophyData.achieved;

        show_debug_message("Trophy info: " + string(_trophyData));
    });

The code sample above will fetch a single trophy data (see TrophyData) and print it to the debugger if the task succeeds.




Back To Top

This function fetches an array of trophy data (see TrophyData). This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_Trophies_Fetch_All(achieved, [callback_success], [callback_failed])
Argument Type Description
achieved boolean Whether or not to fetch only achieved trophies
callback_success function The callback function executed if the request succeeds (array of TrophyData structs is passed as argument) ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_Trophies_Fetch_All(true,
    function(trophiesArray)
    {
        var _trophyData = trophiesArray[0];

        var _id = _trophyData.id;
        var _title = _trophyData.title;
        var _description = _trophyData.description;
        var _difficulty = _trophyData.difficulty;
        var _image_url = _trophyData.image_url;
        var _achieved = _trophyData.achieved;

        show_debug_message("Trophy info: " + string(trophiesArray));
    });

The code sample above will fetch all achieved trophies (see TrophyData) and print it to the debugger if the task succeeds.




Back To Top

This function removes a previously achieved trophy for a particular user. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_Trophies_Remove(trophy_id, [callback_success], [callback_failed])
Argument Type Description
trophy_id string The trophy identifier
callback_success function The callback function executed when the request succeeds ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

if (cheating == true)
    GameJolt_Trophies_Remove(trophyID, function() { show_message_async("You were caught cheating!"); });

The code sample above checks if the variable cheating is true and if so it removes the current trophy from the user and prints a message that he was caught cheating.




Back To Top

This function sets a trophy as achieved for a particular user. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_Trophies_Update(trophy_id, [callback_success], [callback_failed])
gument Type Description
trophy_id string The trophy identifier
callback_success function The callback function executed when the request succeeds ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

if (completeGame == true)
    GameJolt_Trophies_Update(trophyID, function() { show_message_async("You reached the end of the game!"); });

The code sample above checks if the user completed tjat game it updates the current trophy and prints a congratulations message.




Back To Top

This struct is returned as an async result of the call to the following API function calls:

Property Type Description
id real The ID of the trophy.
title string The title of the trophy on the site.
description string The trophy description text.
difficulty string Either "Bronze", "Silver", "Gold" or "Platinum".
image_url string The URL of the trophy's thumbnail image.
achieved boolean/ string Date/time when the trophy was achieved by the user, or false they haven't achieved it yet.