Game Switching and Shortcuts

Welcome to the Facebook Instant Games SDK Tutorials. This series of tutorials covers many aspects of using the Facebook Instant Games SDK.

In this tutorial we will take a look at working with game switching and shortcuts using the Facebook Instant Games SDK.

Game Switching

Game switching is the ability to launch another Facebook Instant Game from the game that the player is currently playing. Note that this may be one of your own games and not that of another developer. This is an incredibly useful tool as it allows you to push players from one game towards another. For example you launch a new game you could push users across all of your existing games to the new game. Switching game is very simple with FBInstant.switchGameAsync():

[sourcecode language=”js”]
FBInstant.switchGameAsync(app_id, data).catch(function(e)
{
});
[/sourcecode]
The app_id is the ID of the game that you would like to switch to, whilst data is optional meta data that can be passed to the entry point of the game when it is launched.

When you call switchGameAsync() the user displayed a pop-up dialog which asks them to confirm the game switch which can be cancelled by the user.

Note that that switch game functionality is not available for iOS devices.

Shortcuts

You can request that the user creates a shortcut to your game on their device, this feature can help to increase retention because your games icon will visible on the players device home screen. Before you can ask the user to create a shortcut you must firstly check that your app can create a short cut. Lets take a look at a quick example of creating shortcuts:

[sourcecode language=”js”]
FBInstant.canCreateShortcutAsync()
.then(function(canCreateShortcut)
{
if (canCreateShortcut)
{
FBInstant.createShortcutAsync()
.then(function() {
// Shortcut was successfully created
})
.catch(function(error) {
// Something went wrong, possibly the user cancelled
});
}
else
{
// Cannot create a shortcut
}
});
[/sourcecode]

Note that when createShortcutAsync() is called the user will be asked to confirm the shortcut creation, which they can cancel.

Leave a Reply