The GameSession object represents the user’s current game session, it contains a unique string that the Turbulenz Services use to identify the user and the game they are playing. The object is required by the majority of the TurbulenzServices methods and associates the created objects with the GameSession. The GameSession object can be used to retrieve a mapping table and application settings for the current game.
The game can also attach metadata to the current game through the setTeamInfo and setPlayerInfo functions. This metadata can be used to display scores, ranks and other information to the user through the game site.
A GameSession object can be created with the TurbulenzServices.createGameSession method.
Any created game session older than a few days will be automatically destroyed when the Local server is started. The Hub and game site automatically destroy any game sessions a week after their last TurbulenzService API request. You must create only one GameSession object and always call its destroy in TurbulenzEngine.onunload.
Required scripts
The GameSession object requires:
/*{{ javascript("jslib/utilities.js") }}*/
/*{{ javascript("jslib/services/gamesession.js") }}*/
/*{{ javascript("jslib/services/turbulenzservices.js") }}*/
Summary
Set the ordered list of teams in the game
Syntax
var teamlist = ['Team A', 'Team B', 'Observers']
gameSession.setTeamInfo(teamlist);
If teams are used within the game then the use of this function to specify team ordering is recommended. If the game does not use teams then it is not necesarry to call this function. Teams with no current members will not be displayed so this function may be called once at the start of the game to give the ordering for all teams.
Summary
Set the per-player info to be displayed by the game site
Syntax
var playerInfo = {
color: "red",
status: "playing as Medic in area 51",
rank: "14th",
score: "$350",
team: "Team A",
sortkey: "14",
};
// A full update of player info
gameSession.setPlayerInfo(playerId, playerInfo);
// A partial update of player info
gameSession.setPlayerInfo(playerId, {score: "$450"});
An object whose properties are used to set the current player’s info. The currently supported info fields are:
This function allows player data such as current score, team, rank, color and status to be displayed by the game site.
Calling this function will add or update the specified fields. To remove all fields which have been previously set, GameSession.removePlayerInfo should be called
Summary
Removes the stored info for a player
Syntax
gameSession.removePlayerInfo(playerId);
This function will remove all data for the specified player that was set with GameSession.setPlayerInfo
Summary
Removes the stored info for all players
Syntax
gameSession.clearAllPlayerInfo();
This function will remove all data for the all players that was set with GameSession.setPlayerInfo
Summary
Destroy a GameSession.
Syntax
//example usage:
gameDestroy = function gameDestroyFn()
{
// destroy Turbulenz engine and JavaScript library objects
...
// first destroy all objects that require the gameSession
mappingTable = null;
userDataManager = null;
leaderboardManager = null;
gameSession.destroy();
gameSession = null;
};
TurbulenzEngine.onunload = gameDestroy;
Once this is called, all objects that take a GameSession object parameter on construction will no longer work, therefore it is advisable to destroy any such objects before calling destroy.