Writing Scripts
brainCloud allows developers to write custom code (in JavaScript) that resides on brainCloud's servers. These scripts can be triggered by:
- Apps - via the Client API
- Other Scripts - via Cloud Code
- Special Features - like Matchmaking
- Private Servers - via the S2S API
- Public Services - via WebHooks
- Other API calls - via the API Hook mechanism
- Time-based - via brainCloud's Scheduling Service
Cloud Code scripts can be created, edited, and tested from the Edit Scripts page of the brainCloud portal.
Pro-tip: Be sure to click on the Cloud Code tab (top-right) to view the examples in this section.
After reviewing these sections, be sure to check out our bridge for step-by-step instructions on how to create your own scripts!
📄️ Runtime Architecture
's Cloud Code service is implemented using an embedded Mozilla Rhino Javascript engine.
📄️ Basic Structure
The simplest scripts are composed of the following elements:
📄️ Functions
Functions are as you would expect in Javascript, with the added limitation that they should be defined before the inline portion of your script begins.
📄️ Calling APIs
To call a API from within a script, you must retrieve the appropriate service proxy from the bridge. You then call the desired method on the proxy.
📄️ Including Shared Scripts
supports shared scripts, which means you can include another script
📄️ Calling Other Scripts
To invoke a script from within another script, simply call the bridge.callScript() method, specifying the name and parameters for the script to call.