-
Notifications
You must be signed in to change notification settings - Fork 0
Sessions
Track when and how long each player is active in your game. You can then view stats such as avg. play time per session, total time played across users, and even see how many people are playing your game in real time.
The following functions are provided for working with sessions:
- GameJolt_Session_Check
- GameJolt_Session_Close
- GameJolt_Session_Open
- GameJolt_Session_Ping_Active
- GameJolt_Session_Ping_Idle
This function checks to see if there is an open session for the user. Can be used to see if a particular user account is active in the game.
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
This function calls
callback_failed
when no open session exists. This behavior is different from other functions which use the callback to indicate an error state.
Syntax:
GameJolt_Session_Check([callback_success], [callback_failed])
Argument | Type | Description |
---|---|---|
callback_success | function | The callback function executed when the request succeeds ✴️ OPTIONAL |
callback_failed | function | The callback function executed if no session is open ✴️ OPTIONAL |
Returns:
N/A
Example:
GameJolt_Session_Check(
function()
{
show_message_async("Session is open")
},
function()
{
GameJolt_Session_Open();
});
The code sample above will check if there is a currently open session and if there is shows the message "Session Connected"
, otherwise attemps to open a new session (using the method GameJolt_Session_Open).
This function closes the active session.
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_Session_Close([callback_success], [callback_failed])
Argument | Type | Description |
---|---|---|
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_Session_Close(undefined, function() { show_debug_message("Session Close Failed"); });
The code sample above tries to close a session and provides a debug message if the session fails to close.
This function opens a game session for a particular user and allows you to tell Game Jolt that a user is playing your game. You must ping the session (using the functions GameJolt_Session_Ping_Active or GameJolt_Session_Ping_Idle) to keep it active and you must close it (using the GameJolt_Session_Close) when you're done with it.
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_Session_Open([callback_success], [callback_failed])
Argument | Type | Description |
---|---|---|
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_Session_Open(
function()
{
show_message_async("Session Opened!!")
},
function(message)
{
show_message_async(message)
});
The code sample above tries to open a new session and provides a message with the regarding its success.
This function pings an open session to tell the system that the session is still being used ( Active ). If the session hasn't been pinged within 120 seconds, the system will close the session and you will have to open another one. It's recommended that you ping about every 30 seconds or so to keep the system from clearing out your session.
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
You can also let the system know the player is idled, using GameJolt_Session_Ping_Idle.
Syntax:
GameJolt_Session_Ping_Active([callback_success], [callback_failed])
Argument | Type | Description |
---|---|---|
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_Session_Ping_Active(undefined,
function(message)
{
show_message_async("Unable to ping");
});
The code sample above tries to ping to the current session with an active user state and shows a message if unable to ping.
This function pings an open session to tell the system that the session is still being used ( Idle ). If the session hasn't been pinged within 120 seconds, the system will close the session and you will have to open another one. It's recommended that you ping about every 30 seconds or so to keep the system from clearing out your session.
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
You can also let the system know the player is active, using GameJolt_Session_Ping_Active.
Syntax:
GameJolt_Session_Ping_Idle([callback_success], [callback_failed])
Argument | Type | Description |
---|---|---|
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_Session_Ping_Idle(undefined,
function(message)
{
show_message_async("Unable to ping");
});
The code sample above tries to ping to the current session with an idle user state and shows a message if unable to ping.
YoYoGames 2023