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

Back To Top

Log in, logout and log in from previously cached user data. Access user's account information to customize your game to your target audience.

Functions

The following functions are provided for working with user and accounts:

Structs

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




Back To Top

This function fetches the logged user data (see UserData). 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_User_FetchMe([callback_success], [callback_failed])
Argument Type Description
callback_success function The callback function executed if the request succeeds (a UserData 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_User_FetchMe(
    function(_userData)
    {
        var _id = _userData.id;
        var _type = _userData.type;
        var _username = _userData.username;
        var _avatar_url = _userData.avatar_url;
        var _signed_up = _userData.signed_up;
        var _signed_up_timestamp = _userData.signed_up_timestamp;
        var _last_logged_in = _userData.last_logged_in;
        var _last_logged_in_timestamp = _userData.last_logged_in_timestamp;
        var _status = _userData.status;
        var _developer_name = _userData.developer_name;
        var _developer_website = _userData.developer_website;
        var _developer_description = _userData.developer_description;

        sprite = sprite_add(_avatar_url, 0, 0, 0, 0, 0);
    },
    function(message)
    {
        show_message_async(message)
    });

The code above will fetch the current logged user data (see UserData) and after successfully retrieving it it starts loading the avatar_url of the user (using the function sprite_add) if it fails it prints an asynchronous message with the error.





Back To Top

This function fetches the user data of a specific user id (see UserData). 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).

ℹ️ TIP

This function is helpful for retrieving information from friends user_id, see GameJolt_Friends.


Syntax:

GameJolt_User_FetchWithUserID(user_id, [callback_success], [callback_failed])
Argument Type Description
user_id string The player's user id
callback_success function The callback function executed if the request succeeds (a UserData 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_User_FetchWithUserID(32323,
    function(_userData)
    {
        var _id = _userData.id;
        var _type = _userData.type;
        var _username = _userData.username;
        var _avatar_url = _userData.avatar_url;
        var _signed_up = _userData.signed_up;
        var _signed_up_timestamp = _userData.signed_up_timestamp;
        var _last_logged_in = _userData.last_logged_in;
        var _last_logged_in_timestamp = _userData.last_logged_in_timestamp;
        var _status = _userData.status;
        var _developer_name = _userData.developer_name;
        var _developer_website = _userData.developer_website;
        var _developer_description = _userData.developer_description;

        sprite = sprite_add(_avatar_url, 0, 0, 0, 0, 0);
    },
    function(message)
    {
        show_message_async(message)
    });

The code above will fetch the user data (see UserData) of a given user id (you can get the user ids of friends using the GameJolt_Friends function) and after successfully retrieving it it starts loading the avatar_url of the user (using the function sprite_add) if it fails it prints an asynchronous message with the error.




Back To Top

This function fetches the user data of a specific username (see UserData). 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_User_FetchWithUserName(username, [callback_success], [callback_failed])
Argument Type Description
username string The player's username
callback_success function The callback function executed if the request succeeds (a UserData 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_User_FetchWithUserID("gameMaster",
    function(_userData)
    {
        var _id = _userData.id;
        var _type = _userData.type;
        var _username = _userData.username;
        var _avatar_url = _userData.avatar_url;
        var _signed_up = _userData.signed_up;
        var _signed_up_timestamp = _userData.signed_up_timestamp;
        var _last_logged_in = _userData.last_logged_in;
        var _last_logged_in_timestamp = _userData.last_logged_in_timestamp;
        var _status = _userData.status;
        var _developer_name = _userData.developer_name;
        var _developer_website = _userData.developer_website;
        var _developer_description = _userData.developer_description;

        sprite = sprite_add(_avatar_url, 0, 0, 0, 0, 0);
    },
    function(message)
    {
        show_message_async(message)
    });

The code above will fetch the user data (see UserData) of a given username and after successfully retrieving it it starts loading the avatar_url of the user (using the function sprite_add) if it fails it prints an asynchronous message with the error.




Back To Top

This function checks if the user is currently logged in.


Syntax:

GameJolt_User_IsLogged()

Returns:

Bool

Example:

if (GameJolt_User_IsLogged())
{
    GameJolt_User_LogOut();
}
else GameJolt_User_LogIn_FromCache();

The code sample above will check if the user is currently logged in and if so it logs the user out (using the function GameJolt_User_LogOut) otherwise it will log the user in with the information stored in cache (using the function GameJolt_User_LogIn_FromCache).




Back To Top

This function authenticates the user's information. This should be done before you make any calls for the user, to make sure the user's credentials (username and token) are valid. 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).

ℹ️ NOTE

You can use GameJolt_User_LogIn_FromCache to login with cached data over the next sessions.


Syntax:

GameJolt_User_LogIn(user_name, game_token, [callback_success], [callback_failed])
Argument Type Description
user_name string The user's username.
game_token string The user's token.
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:

GameJolt_User_LogIn(user, token,
    function()
    {
        instance_create_depth(200, 250, 0, objPlayer)
    },
    function(message)
    {
        show_message_async("Error: " + message)
    });

The code sample above will login a user to a specific game using the game token for that game. After a successful login it creates an instance of objPlayer on the room (using the instance_create_depth function), otherwise it will display an error message.




Back To Top

This function logs in using the cached data from previous sessions (see GameJolt_User_LogIn).


Syntax:

GameJolt_User_LogIn_FromCache()

Returns:

Bool

Example:

if (GameJolt_User_LogIn_FromCache())
    instance_create_depth(200, 250, 0, objPlayer)

The code sample above will try to login a user to a specific game using data cached from a previous session. If the log in is successful it creates an instance of objPlayer inside the room (using the instance_create_depth function).




Back To Top

This function closes a session and clears its cache.


Syntax:

GameJolt_User_LogOut()

Returns:

N/A

Example:

if (GameJolt_User_IsLogged())
    GameJolt_User_LogOut()

The code sample above will check if the user is currently logged in (using the GameJolt_User_IsLogged function) and if so it logs the user out.




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 user.
type string The type of user. Can be "User", "Developer", "Moderator", or "Administrator".
username string The user's username.
avatar_url string The URL of the user's avatar.
signed_up string How long ago the user signed up (example: "1 year ago")
signed_up_timestamp real The timestamp (in seconds) of when the user signed up.
last_logged_in string How long ago the user was last logged in. Will be "Online Now" if the user is currently online. (example: "2 minutes ago")
last_logged_in_timestamp real The timestamp (in seconds) of when the user was last logged in.
status string "Active" if the user is still a member of the site. "Banned" if they've been banned.
developer_name string The user's display name.
developer_website string The user's website (or empty string if not specified)
developer_description string The user's profile markdown description.