Cloud Code


The Configurator > Cloud Code page is designed to help you quickly write and manage the cloud code scripts for the custom logic you will use to control the behavior of configurable components you build into your game. Cloud code execution is triggered at key interception points in the flow of your game-play's interaction with the service. You can attach these cloud code scripts to:

The Scripts panel organizes these types into expandable folders. You can click to expand a folder, such as Requests, select the request to which you want to attach a cloud code script, and then use a JavaScript editor to write and save your script.

The Scripts panel also carries folders for other categories of scripts you can create when building the custom code you need to achieve the game-play experience you want for your players:

Important! Before you start to create your cloud code scripts and for more on the role of Cloud Code within the service, we strongly recommend that you first read the Cloud Code page in the Key Concepts section.

Working with the Scripts Panel

The Scripts section is split into separate categories, which are further explained below. You can expand a category to select an individual item to which you want to attach your Cloud Code script, such as an Event or Request.

There are five main option buttons at the bottom of the Scripts panel:

Inserting and Accessing Cloud Code

To access the JavaScript editor and write Cloud Code:

1. In the Scripts panel, click to expand the relevant folder and show the individual scripts contained in the folder.

Note: If you open the Events or Challenge Events folder and the folder is empty, this is because you haven't yet created any Events for your game.

2. Select the script to which you want to attach Cloud Code. The JavaScript editor opens for that script.

3. Write your script and save it.

4. If you want to modify the Cloud Code script at any time, follow these steps to re-open the JavaScript editor for the script. You can use the Save, Close, and Delete buttons at the bottom of the editor to manage your scripts.

Keyboard Shortcuts to Save! You can also save your scripts using standard key press combinations, CMD+S on OSX and CTRL+S on Windows and Linux.

Keyboard Shortcuts List! For a list of keyboard shortcuts that you can use in the Cloud Code Editor see below

Refreshing the Scripts Panel

For some Scripts categories, you can use the plus icon to quickly add a new item, such as adding a new Event. This saves you having to navigate away from the Cloud Code page and then come back to the page to add your Cloud Code script.

However, you might be working on your game in several tabs at once or you might be developing your game along with several Collaborators. If you've added a new Event using the plus icon in one tab and switch to another, you must click the refresh icon to see the added Event in the Scripts panel list. Similarly, if one of your Collaborators has added an Event, you must refresh the Scripts panel to see that Event.

Cloud Code Tutorials? For a rich set of tutorials on how to work with Cloud Code, go here.

Scripts Categories

Click to expand any of the Scripts categories and select the interception point to which you want to attach your Cloud Code.

Cloud Code Best Practices! Before you start to build out the Cloud Code for your game, we strongly recommend that you read the Cloud Code Best Practices guide. This will help you to avoid creating Cloud Code structures that might compromise your game's performance and suggests ways in which you can check and review your Cloud Code's performance and efficiency.


The Events list contains an entry for each Event you have created within the GameSparks platform:

Challenge Events

The Challenge Events list contains an entry for each Event you have created within the GameSparks platform:

    var myChallenge = Spark.getChallenge(;

Challenge Turn Taken Messages! Note that if you submit a LogChallengeEventRequest, then a ChallengeTurnTakenMessage will be automatically generated. This happens to ensure that you are notified if any change to the Challenge is effected by the request. For more details on messaging for Challenges, see the Understanding and Testing Challenges tutorial.


The Requests list contains an entry for each Request you can call within the GameSparks platform:

Adding Common Functionality! LogEventRequest and LogChallengeEventRequest are global scripts that will be executed for these request types before a specific script is called for each Event. This allows you to add a common functionality to all Events.


The Responses list contains an entry for each Response that can be returned from the GameSparks platform:

User Messages

The User Messages list contains an entry for each Message that can be returned from the GameSparks platform:

Global Messages

The Global Messages list contains an entry for each Message that can be returned from the GameSparks platform:


The System tab contains a number of System Events that are able to trigger some JavaScript Cloud Code:



Modules allow you to create your own libraries of JavaScript that can be included within other scripts. This allows you to separate common functionality that needs to be shared between scripts into a single module that can be included.

    if(something) {
    } else {

Realtime Scripts

Realtime Scripts are listed here:

Realtime Modules

Realtime Modules allow you to create your own libraries of JavaScript that can be included within other Realtime scripts. This allows you to separate common functionality that needs to be shared between scripts into a single Realtime module that can be included.

Realtime modules use CommonJS module loading. A primer for CommonJS can be found here.

To author a Realtime module, you must define the objects you want to export. This is done using "module.exports". You can export multiple items from a single module:

module.exports.fiz = function () {
} = function () {

To include the Realtime Module in a Realtime Script, the require function should be used as follows:

var theModule = require("MODULE_NAME");
var fizResult = theModule.fiz();
var buzzResult =;

At this point, theModule represents the exports from the Realtime Module

Cloud Code Editor Keyboard Shortcuts

This section lists keyboard shortcuts you can use when working in the Cloud Code Editor.


Windows/Linux Mac Action
Ctrl+A Command+A Select All
Shift+Left Command+Left Select Left
Shift+Right Command+Right Select Right
Ctrl+Shift+Left Option+Shift+Left Select Word Left
Ctrl+Shift+Right Option+Shift+Right Select Word Right
Shift+Home Shift+Home Select Line Start
Shift+End Shift+End Select Line End
Alt+Shift+Left Command+Shift+Left Select to Line Start
Alt+Shift+Right Command+Shift+Right Select to Line End
Shift+Up Shift+Up Select Up
Shift+Down Shift+Down Select Down
Ctrl+Shift+Home Command+Shift+Up Select to Start
Ctrl+Shift+End Command+Shift+Down Select to End
Ctrl+Shift+D Command+Shift+D Duplicate Selection

Line Operation

Windows/Linux Mac Action
Ctrl+D Command+D Remove Line
Alt+Shift+Down Command+Option+Down Copy Lines Down
Alt+Shift+Up Command+Option+Up Copy Lines Up
Alt+Down Option+Down Move Lines Down
Alt+Up Option+Up Move Lines Up
Alt+Delete Ctrl+K Remove to Line End
Alt+Backspace Command+Backspace Remove to Line Start
Ctrl+Backspace Option+Backspace, Ctrl+Option+Backspace Remove Word Left
Ctrl+Delete Option+Delete Remove Word Right
--- Ctrl+O Split Line
Ctrl+M+/ --- Comment/Uncomment Line

Go To

Windows/Linux Mac Action
Ctrl+L, Ctrl+M+L Command+L, Command+M+L Go to Line
Left Left, Ctrl+B Go to Left
Right Right, Ctrl+F Go to Right
Ctrl+Left Option+Left Go to Word Left
Ctrl+Right Option+Right Go to Word Right
Up Up, Ctrl+P Go to Line Up
Down Down, Ctrl+N Go to Line Down
Alt+Left, Home Command+Left, Home, Ctrl+A Go to Line Start
Alt+Right, End Command+Right, End, Ctrl+E Go to Line End
Ctrl+Home Command+Home, Command+Up Go to Start
Ctrl+End Command+End, Command+Down Go to End
Ctrl+Down Command+Down Scroll Line Down
Ctrl+Up --- Scroll Line Up


Windows/Linux Mac Action
Ctrl+F, Ctrl+M+F Command+F Find
Ctrl+H Command+Option+F Replace
Ctrl+K, Command+G Find Next
Ctrl+Shift+K Command+Shift+G Find Previous
Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here